Skip to content

Commit

Permalink
Merge 11feae3 into 307affc
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas Pickering committed Mar 5, 2021
2 parents 307affc + 11feae3 commit 7afa9e6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions index.js
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
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 7afa9e6

Please sign in to comment.