diff --git a/index.js b/index.js index 1690844c..41eb7602 100644 --- a/index.js +++ b/index.js @@ -162,7 +162,7 @@ function prettyFactory (options) { line += ':' } - if (prettifiedMessage) { + if (prettifiedMessage !== undefined) { if (line.length > 0) { line = `${line} ${prettifiedMessage}` } else { @@ -186,7 +186,7 @@ function prettyFactory (options) { if (singleLine) line += EOL line += prettifiedErrorLog } else if (!hideObject) { - const skipKeys = [messageKey, levelKey, timestampKey].filter(key => typeof log[key] === 'string' || typeof log[key] === 'number') + const skipKeys = [messageKey, levelKey, timestampKey].filter(key => typeof log[key] === 'string' || typeof log[key] === 'number' || typeof log[key] === 'boolean') const prettifiedObject = prettifyObject({ input: log, skipKeys, diff --git a/lib/utils.js b/lib/utils.js index 159dc510..db3536ba 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -280,7 +280,7 @@ function prettifyMessage ({ log, messageFormat, messageKey = MESSAGE_KEY, colori return colorizer.message(msg) } if (messageKey in log === false) return undefined - if (typeof log[messageKey] !== 'string') return undefined + if (typeof log[messageKey] !== 'string' && typeof log[messageKey] !== 'number' && typeof log[messageKey] !== 'boolean') return undefined return colorizer.message(log[messageKey]) } diff --git a/test/basic.test.js b/test/basic.test.js index 5dfc05f5..9986811c 100644 --- a/test/basic.test.js +++ b/test/basic.test.js @@ -118,6 +118,70 @@ test('basic prettifier tests', (t) => { log.info('foo') }) + t.test('can print message key value when its a string', (t) => { + t.plan(1) + const pretty = prettyFactory() + const log = pino({}, new Writable({ + write (chunk, enc, cb) { + const formatted = pretty(chunk.toString()) + t.equal( + formatted, + `[${formattedEpoch}] INFO (${pid}): baz\n` + ) + cb() + } + })) + log.info('baz') + }) + + t.test('can print message key value when its a number', (t) => { + t.plan(1) + const pretty = prettyFactory() + const log = pino({}, new Writable({ + write (chunk, enc, cb) { + const formatted = pretty(chunk.toString()) + t.equal( + formatted, + `[${formattedEpoch}] INFO (${pid}): 42\n` + ) + cb() + } + })) + log.info(42) + }) + + t.test('can print message key value when its a Number(0)', (t) => { + t.plan(1) + const pretty = prettyFactory() + const log = pino({}, new Writable({ + write (chunk, enc, cb) { + const formatted = pretty(chunk.toString()) + t.equal( + formatted, + `[${formattedEpoch}] INFO (${pid}): 0\n` + ) + cb() + } + })) + log.info(0) + }) + + t.test('can print message key value when its a boolean', (t) => { + t.plan(1) + const pretty = prettyFactory() + const log = pino({}, new Writable({ + write (chunk, enc, cb) { + const formatted = pretty(chunk.toString()) + t.equal( + formatted, + `[${formattedEpoch}] INFO (${pid}): true\n` + ) + cb() + } + })) + log.info(true) + }) + t.test('can use different message keys', (t) => { t.plan(1) const pretty = prettyFactory({ messageKey: 'bar' })