Skip to content

Commit

Permalink
Deal with prettifier function returning undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
jsumners committed Apr 28, 2018
1 parent 214fcd1 commit 86c40a3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 4 additions & 2 deletions bin.js
Expand Up @@ -24,12 +24,14 @@ args
.example('cat log | pino-pretty -t', 'To convert Epoch timestamps to ISO timestamps use the -t option')
.example('cat log | pino-pretty -t "SYS:yyyy-mm-dd HH:MM:ss"', 'To convert Epoch timestamps to local timezone format use the -t option with "SYS:" prefixed format string')
.example('cat log | pino-pretty -l', 'To flip level and time/date in standard output use the -l option')
.example('cat log | pino-pretty -s \'msg == `hello world`\'', 'Only prints messages with msg equals to \'hello world\'')
.example('cat log | pino-pretty -s "msg == \'hello world\'"', 'Only prints messages with msg equals to \'hello world\'')

const opts = args.parse(process.argv)
const pretty = prettyFactory(opts)
const prettyTransport = through.obj(function (chunk, enc, cb) {
process.stdout.write(pretty(chunk.toString()))
const line = pretty(chunk.toString())
if (line === undefined) return cb()
process.stdout.write(line)
cb()
})

Expand Down
9 changes: 9 additions & 0 deletions test/basic.test.js
Expand Up @@ -419,5 +419,14 @@ test('basic prettifier tests', (t) => {
log.info({ foo: { bar: true } }, 'foo')
})

t.test('handles `undefined` return values', (t) => {
t.plan(2)
const pretty = prettyFactory({search: 'msg == \'hello world\''})
let formatted = pretty(`{"msg":"nope", "time":${epoch}, "level":30, "v":1}`)
t.is(formatted, undefined)
formatted = pretty(`{"msg":"hello world", "time":${epoch}, "level":30, "v":1}`)
t.is(formatted, `[${epoch}] INFO: hello world\n`)
})

t.end()
})

0 comments on commit 86c40a3

Please sign in to comment.