diff --git a/lib/pretty.js b/lib/pretty.js index 5284d7b..a2b6813 100644 --- a/lib/pretty.js +++ b/lib/pretty.js @@ -147,11 +147,13 @@ function pretty (inputData) { this.messageKey, this.levelKey, this.timestampKey - ].filter(key => { - return typeof log[key] === 'string' || - typeof log[key] === 'number' || - typeof log[key] === 'boolean' - }) + ] + .map((key) => key.replaceAll(/\\/g, '')) + .filter(key => { + return typeof log[key] === 'string' || + typeof log[key] === 'number' || + typeof log[key] === 'boolean' + }) const prettifiedObject = prettifyObject({ log, skipKeys, diff --git a/test/basic.test.js b/test/basic.test.js index a62abbf..3437d1e 100644 --- a/test/basic.test.js +++ b/test/basic.test.js @@ -218,6 +218,22 @@ test('basic prettifier tests', (t) => { log.info({ msg: 'foo', bar: 'warn' }) }) + t.test('can use nested level keys', (t) => { + t.plan(1) + const pretty = prettyFactory({ levelKey: 'log\\.level' }) + const log = pino({}, new Writable({ + write (chunk, enc, cb) { + const formatted = pretty(chunk.toString()) + t.equal( + formatted, + `[${formattedEpoch}] WARN (${pid}): foo\n` + ) + cb() + } + })) + log.info({ msg: 'foo', 'log.level': 'warn' }) + }) + t.test('can use a customPrettifier on default level output', (t) => { t.plan(1) const veryCustomLevels = {