Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tools): log[level] compatible with when first argument is undefined (fix #1555) #1565

Merged
merged 1 commit into from Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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