Skip to content

Commit

Permalink
fix: unescape \\ for levelKey (#538)
Browse files Browse the repository at this point in the history
closes #456
  • Loading branch information
eliw00d authored Nov 8, 2024
1 parent 163ef0b commit 2a85c0d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/pretty.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 16 additions & 0 deletions test/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit 2a85c0d

Please sign in to comment.