Skip to content

Commit

Permalink
Fixes issue with nested keys (#1198)
Browse files Browse the repository at this point in the history
* fix: fixes issue with nested keys

* chore: use strictSame in nested key test
  • Loading branch information
sameer-coder authored Oct 29, 2021
1 parent f19a27f commit 43906c7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ function asJson (obj, msg, num, time) {
}
}

if (this[nestedKeySym]) {
if (this[nestedKeySym] && propStr) {
// place all the obj properties under the specified key
// the nested key is already formatted from the constructor
return data + this[nestedKeyStrSym] + propStr.slice(1) + '}' + msgStr + end
Expand Down
18 changes: 18 additions & 0 deletions test/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -712,3 +712,21 @@ test('correctly log number', async (t) => {
const { msg } = await once(stream, 'data')
t.equal(msg, 42)
})

test('nestedKey should not be used for non-objects', async ({ strictSame }) => {
const stream = sink()
const message = 'hello'
const nestedKey = 'stuff'
const instance = pino({
nestedKey
}, stream)
instance.info(message)
const result = await once(stream, 'data')
delete result.time
strictSame(result, {
pid,
hostname,
level: 30,
msg: message
})
})

0 comments on commit 43906c7

Please sign in to comment.