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: pass error-like objects (#505) #506

Merged
merged 1 commit into from
Apr 29, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/pretty.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ function pretty (inputData) {
}

// pino@7+ does not log this anymore
if (log.type === 'Error' && log.stack) {
if (log.type === 'Error' && typeof log.stack === 'string') {
const prettifiedErrorLog = prettifyErrorLog({ log, context: this.context })
if (this.singleLine) line += this.EOL
line += prettifiedErrorLog
Expand Down
26 changes: 26 additions & 0 deletions test/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,32 @@ test('basic prettifier tests', (t) => {
t.equal(arst, 'INFO: hello world\n')
})

t.test('log error-like object', (t) => {
t.plan(7)
const expectedLines = [
' type: "Error"',
' message: "m"',
' stack: [',
' "line1",',
' "line2"',
' ]'
]
const pretty = prettyFactory()
const log = pino({}, new Writable({
write (chunk, enc, cb) {
const formatted = pretty(chunk.toString())
const lines = formatted.split('\n')
t.equal(lines.length, expectedLines.length + 2)
lines.shift(); lines.pop()
for (let i = 0; i < lines.length; i += 1) {
t.equal(lines[i], expectedLines[i])
}
cb()
}
}))
log.error({ type: 'Error', message: 'm', stack: ['line1', 'line2'] })
})

t.test('include should override ignore', (t) => {
t.plan(1)
const pretty = prettyFactory({ ignore: 'time,level', include: 'time,level' })
Expand Down