Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions start.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,13 @@ async function runFastify (args, additionalOptions, serverOptions, serverModule)
options.trustProxy = opts.trustProxy
}

// fastify v5 only accepts a configuration object in `logger`;
// logger instances must be passed via `loggerInstance`
if (options.logger && typeof options.logger.child === 'function') {
options.loggerInstance = options.logger
delete options.logger
}

const fastify = Fastify(options)

if (opts.prefix) {
Expand Down
5 changes: 5 additions & 0 deletions test/data/custom-logger-instance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict'

const pino = require('pino')

module.exports = pino({ level: 'warn' })
11 changes: 11 additions & 0 deletions test/start.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,17 @@ test('should support custom logger configuration in ESM', async t => {
t.pass('server closed')
})

test('should support a logger instance from a logging module', async t => {
t.plan(2)

const argv = ['-L', './test/data/custom-logger-instance.js', './examples/plugin.js']
const fastify = await start.start(argv)
t.equal(fastify.log.level, 'warn')

await fastify.close()
t.pass('server closed')
})

test('preloading a built-in module works', async t => {
t.plan(1)

Expand Down