Skip to content

Commit

Permalink
fix: allow logging numbers when mergeHapiLogData is true (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
AdriVanHoudt committed Mar 15, 2022
1 parent 7907e21 commit 2b006e2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -252,7 +252,7 @@ async function register (server, options) {

var logObject
if (mergeHapiLogData) {
if (typeof data === 'string') {
if (typeof data === 'string' || typeof data === 'number') {
data = { [messageKey]: data }
}

Expand Down
24 changes: 24 additions & 0 deletions test.js
Expand Up @@ -1336,6 +1336,30 @@ experiment('logging with mergeHapiLogData option enabled', () => {
await finish
})

test('when data is a number, merge it as msg property', async () => {
const server = getServer()
let done
const finish = new Promise(function (resolve, reject) {
done = resolve
})
const stream = sink(data => {
expect(data).to.include({ msg: 1 })
done()
})
const plugin = {
plugin: Pino,
options: {
stream: stream,
level: 'info',
mergeHapiLogData: true
}
}

await server.register(plugin)
server.log(['info'], 1)
await finish
})

test('respects `messageKey` option', async () => {
const server = getServer()
let done
Expand Down

0 comments on commit 2b006e2

Please sign in to comment.