Comparing version 6.6.1 to 6.7.0
@@ -156,3 +156,3 @@ # API | ||
* `censor` (String|Function|Undefined): Optional. When supplied as a String the `censor` option will overwrite keys which are to be redacted. When set to `undefined` the the key will be removed entirely from the object. | ||
The `censor` option may also be a mapping function. The (synchronous) mapping function is called with the unredacted value. The value returned from the mapping function becomes the applied censor value. Default: `'[Redacted]'` | ||
The `censor` option may also be a mapping function. The (synchronous) mapping function has the signature `(value, path) => redactedValue` and is called with the unredacted `value` and `path` to the key being redacted, as an array. For example given a redaction path of `a.b.c` the `path` argument would be `['a', 'b', 'c']`. The value returned from the mapping function becomes the applied censor value. Default: `'[Redacted]'` | ||
value synchronously. | ||
@@ -159,0 +159,0 @@ Default: `'[Redacted]'` |
@@ -79,9 +79,21 @@ 'use strict' | ||
const topCensor = (...args) => | ||
typeof censor === 'function' ? serialize(censor(...args)) : serialize(censor) | ||
const topCensor = (...args) => { | ||
return typeof censor === 'function' ? serialize(censor(...args)) : serialize(censor) | ||
} | ||
return [...Object.keys(shape), ...Object.getOwnPropertySymbols(shape)].reduce((o, k) => { | ||
// top level key: | ||
if (shape[k] === null) o[k] = topCensor | ||
else o[k] = fastRedact({ paths: shape[k], censor, serialize, strict }) | ||
if (shape[k] === null) { | ||
o[k] = (value) => topCensor(value, [k]) | ||
} else { | ||
const wrappedCensor = typeof censor === 'function' ? (value, path) => { | ||
return censor(value, [k, ...path]) | ||
} : censor | ||
o[k] = fastRedact({ | ||
paths: shape[k], | ||
censor: wrappedCensor, | ||
serialize, | ||
strict | ||
}) | ||
} | ||
return o | ||
@@ -88,0 +100,0 @@ }, result) |
{ | ||
"name": "pino", | ||
"version": "6.6.1", | ||
"version": "6.7.0", | ||
"description": "super fast, all natural json logger", | ||
@@ -88,3 +88,3 @@ "main": "pino.js", | ||
"dependencies": { | ||
"fast-redact": "^2.0.0", | ||
"fast-redact": "^3.0.0", | ||
"fast-safe-stringify": "^2.0.7", | ||
@@ -91,0 +91,0 @@ "flatstr": "^1.0.12", |
@@ -222,2 +222,33 @@ 'use strict' | ||
test('redact.censor option – can be a function that accepts value and path arguments', async ({ is }) => { | ||
const stream = sink() | ||
const instance = pino({ redact: { paths: ['topLevel'], censor: (value, path) => value + ' ' + path.join('.') } }, stream) | ||
instance.info({ | ||
topLevel: 'test' | ||
}) | ||
const { topLevel } = await once(stream, 'data') | ||
is(topLevel, 'test topLevel') | ||
}) | ||
test('redact.censor option – can be a function that accepts value and path arguments (nested path)', async ({ is }) => { | ||
const stream = sink() | ||
const instance = pino({ redact: { paths: ['req.headers.cookie'], censor: (value, path) => value + ' ' + path.join('.') } }, stream) | ||
instance.info({ | ||
req: { | ||
id: 7915, | ||
method: 'GET', | ||
url: '/', | ||
headers: { | ||
host: 'localhost:3000', | ||
connection: 'keep-alive', | ||
cookie: 'SESSID=298zf09hf012fh2; csrftoken=u32t4o3tb3gg43; _gat=1;' | ||
}, | ||
remoteAddress: '::ffff:127.0.0.1', | ||
remotePort: 58022 | ||
} | ||
}) | ||
const { req } = await once(stream, 'data') | ||
is(req.headers.cookie, 'SESSID=298zf09hf012fh2; csrftoken=u32t4o3tb3gg43; _gat=1; req.headers.cookie') | ||
}) | ||
test('redact.remove option – removes both key and value', async ({ is }) => { | ||
@@ -224,0 +255,0 @@ const stream = sink() |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
312499
7325
+ Addedfast-redact@3.5.0(transitive)
- Removedfast-redact@2.1.0(transitive)
Updatedfast-redact@^3.0.0