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
4 changes: 4 additions & 0 deletions start.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ async function runFastify (args, additionalOptions, serverOptions, serverModule)
options = deepmerge(options, file.options)
}

if (options.loggerInstance) {
delete options.logger
}

if (opts.trustProxy) {
options.trustProxy = opts.trustProxy
}
Expand Down
25 changes: 25 additions & 0 deletions test/data/plugin-with-logger-instance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict'

const messages = []

function noop () {}

const loggerInstance = {
level: 'info',
messages,
info (msg) { messages.push(msg) },
error: noop,
debug: noop,
fatal: noop,
warn: noop,
trace: noop,
child () { return this }
}

module.exports = function (fastify, options, next) {
next()
}

module.exports.options = {
loggerInstance
}
31 changes: 31 additions & 0 deletions test/helper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,37 @@ test('should merge the CLI and FILE configs', async t => {
t.assert.strictEqual(lines[0].foo, '***')
})

test('should accept a loggerInstance in the server options', async t => {
const argv = ['./examples/plugin.js']
const messages = []
function noop () {}
const loggerInstance = {
level: 'info',
info (msg) { messages.push(msg) },
error: noop,
debug: noop,
fatal: noop,
warn: noop,
trace: noop,
child () { return this }
}

const app = await helper.build(argv, {}, { loggerInstance })
t.after(() => app.close())
app.log.info('hello')
t.assert.deepStrictEqual(messages, ['hello'])
})

test('should accept a loggerInstance in the plugin options', async t => {
const argv = ['./test/data/plugin-with-logger-instance.js', '--options']
const { options } = require('./data/plugin-with-logger-instance')

const app = await helper.build(argv, {})
t.after(() => app.close())
app.log.info('hello')
t.assert.deepStrictEqual(options.loggerInstance.messages, ['hello'])
})

test('should ensure can access all decorators', async t => {
const argv = ['./examples/plugin.js']
const app = await helper.build(argv, { skipOverride: true })
Expand Down
Loading