Skip to content

Commit

Permalink
fix(tools): log[level] compatible with when first argument is undefin…
Browse files Browse the repository at this point in the history
…ed (fix #1555) (#1565)
  • Loading branch information
sun0day committed Sep 27, 2022
1 parent 43b9c6d commit e6d355c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/tools.js
Expand Up @@ -53,7 +53,7 @@ function genLog (level, hook) {
}
this[writeSym](o, format(msg, formatParams, this[formatOptsSym]), level)
} else {
this[writeSym](null, format(o, n, this[formatOptsSym]), level)
this[writeSym](null, format(o === undefined ? n.shift() : o, n, this[formatOptsSym]), level)
}
}
}
Expand Down
16 changes: 16 additions & 0 deletions test/basic.test.js
Expand Up @@ -109,6 +109,22 @@ function levelTest (name, level) {
same(Object.keys(obj), ['hello'])
})

test(`passing a undefined and a string at level ${name}`, async ({ equal, same }) => {
const stream = sink()
const instance = pino(stream)
instance.level = name
instance[name](undefined, 'a string')
const result = await once(stream, 'data')
equal(new Date(result.time) <= new Date(), true, 'time is greater than Date.now()')
delete result.time
same(result, {
pid,
hostname,
level,
msg: 'a string'
})
})

test(`overriding object key by string at level ${name}`, async ({ equal, same }) => {
const stream = sink()
const instance = pino(stream)
Expand Down

0 comments on commit e6d355c

Please sign in to comment.