Skip to content

Commit

Permalink
Fix trailing space in singleLine mode (#165)
Browse files Browse the repository at this point in the history
A bug in #158 left a trailing space on lines that had no extra log fields with singleLine=true. This commit fixes that, and updates a test accordingly.
  • Loading branch information
Lucas Pickering committed Mar 8, 2021
1 parent 307affc commit 5af4a27
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ module.exports = function prettyFactory (options) {
}
}

if (line.length > 0) {
line += (singleLine ? ' ' : EOL)
if (line.length > 0 && !singleLine) {
line += EOL
}

if (log.type === 'Error' && log.stack) {
Expand All @@ -157,6 +157,11 @@ module.exports = function prettyFactory (options) {
singleLine,
colorizer
})

// In single line mode, include a space only if prettified version isn't empty
if (singleLine && !/^\s$/.test(prettifiedObject)) {
line += ' '
}
line += prettifiedObject
}

Expand Down
2 changes: 1 addition & 1 deletion test/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ test('basic prettifier tests', (t) => {
const log = pino({}, new Writable({
write (chunk, enc, cb) {
const formatted = pretty(chunk.toString())
t.is(formatted, `[${epoch}] INFO (${pid} on ${hostname}): message \n`)
t.is(formatted, `[${epoch}] INFO (${pid} on ${hostname}): message\n`)
cb()
}
}))
Expand Down

0 comments on commit 5af4a27

Please sign in to comment.