Skip to content

Commit 2a85c0d

Browse files
authored
fix: unescape \\ for levelKey (#538)
closes #456
1 parent 163ef0b commit 2a85c0d

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

lib/pretty.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,13 @@ function pretty (inputData) {
147147
this.messageKey,
148148
this.levelKey,
149149
this.timestampKey
150-
].filter(key => {
151-
return typeof log[key] === 'string' ||
152-
typeof log[key] === 'number' ||
153-
typeof log[key] === 'boolean'
154-
})
150+
]
151+
.map((key) => key.replaceAll(/\\/g, ''))
152+
.filter(key => {
153+
return typeof log[key] === 'string' ||
154+
typeof log[key] === 'number' ||
155+
typeof log[key] === 'boolean'
156+
})
155157
const prettifiedObject = prettifyObject({
156158
log,
157159
skipKeys,

test/basic.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,22 @@ test('basic prettifier tests', (t) => {
218218
log.info({ msg: 'foo', bar: 'warn' })
219219
})
220220

221+
t.test('can use nested level keys', (t) => {
222+
t.plan(1)
223+
const pretty = prettyFactory({ levelKey: 'log\\.level' })
224+
const log = pino({}, new Writable({
225+
write (chunk, enc, cb) {
226+
const formatted = pretty(chunk.toString())
227+
t.equal(
228+
formatted,
229+
`[${formattedEpoch}] WARN (${pid}): foo\n`
230+
)
231+
cb()
232+
}
233+
}))
234+
log.info({ msg: 'foo', 'log.level': 'warn' })
235+
})
236+
221237
t.test('can use a customPrettifier on default level output', (t) => {
222238
t.plan(1)
223239
const veryCustomLevels = {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy