Skip to content

Commit d1d0571

Browse files
authoredNov 23, 2021
append missing eol before appending prettified error object when singleLine=true (#272)
1 parent f96075f commit d1d0571

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed
 

‎index.js

+1
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ function prettyFactory (options) {
146146
ident: IDENT,
147147
eol: EOL
148148
})
149+
if (singleLine) line += EOL
149150
line += prettifiedErrorLog
150151
} else if (!hideObject) {
151152
const skipKeys = [messageKey, levelKey, timestampKey].filter(key => typeof log[key] === 'string' || typeof log[key] === 'number')

‎test/error-objects.test.js

+23-1
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,29 @@ test('error like objects tests', { only: true }, (t) => {
281281
log.error(error)
282282
})
283283

284-
t.test('errorProps: legacy error object at top level', { only: true }, function (t) {
284+
t.test('prettifies legacy error object at top level when singleLine=true', function (t) {
285+
t.plan(4)
286+
const pretty = prettyFactory({ singleLine: true })
287+
const err = Error('hello world')
288+
const expected = err.stack.split('\n')
289+
expected.unshift(err.message)
290+
291+
const log = pino({}, new Writable({
292+
write (chunk, enc, cb) {
293+
const formatted = pretty(chunk.toString())
294+
const lines = formatted.split('\n')
295+
t.equal(lines.length, expected.length + 1)
296+
t.equal(lines[0], `[${epoch}] INFO (${pid} on ${hostname}): ${expected[0]}`)
297+
t.equal(lines[1], ` ${expected[1]}`)
298+
t.equal(lines[2], ` ${expected[2]}`)
299+
cb()
300+
}
301+
}))
302+
303+
log.info({ type: 'Error', stack: err.stack, msg: err.message })
304+
})
305+
306+
t.test('errorProps: legacy error object at top level', function (t) {
285307
const pretty = prettyFactory({ errorProps: '*' })
286308
const expectedLines = [
287309
'INFO:',

0 commit comments

Comments
 (0)
Please sign in to comment.