Add redact to pino options

This commit is contained in:
Alexandre Ferrando
2018-11-18 18:58:44 +01:00
parent 2b4c81593a
commit c3bb846fcd
2 changed files with 41 additions and 0 deletions
+20
View File
@@ -173,6 +173,20 @@ declare namespace P {
* Warning: this option may not be supported by downstream transports.
*/
useOnlyCustomLevels?: boolean;
/**
* As an array, the redact option specifies paths that should have their values redacted from any log output.
*
* Each path must be a string using a syntax which corresponds to JavaScript dot and bracket notation.
*
* If an object is supplied, three options can be specified:
*
* paths (String[]): Required. An array of paths
* censor (String): Optional. A value to overwrite key which are to be redacted. Default: '[Redacted]'
* remove (Boolean): Optional. Instead of censoring the value, remove both the key and the value. Default: false
*/
redact?: string[] | redactOptions;
/**
* When defining a custom log level via level, set to an integer value to define the new level. Default: `undefined`.
*/
@@ -420,4 +434,10 @@ declare namespace P {
(msg: string, ...args: any[]): void;
(obj: object, msg?: string, ...args: any[]): void;
}
interface redactOptions {
paths: string[];
censor?: string;
remove?: boolean;
}
}
+21
View File
@@ -102,3 +102,24 @@ const handler = pino.final(logExtreme, (err: Error, finalLogger: pino.BaseLogger
});
handler(new Error('error'));
const redacted = pino({
redact: ['path']
});
redacted.info({
msg: 'logged with redacted properties',
path: 'Not shown'
});
const anotherRedacted = pino({
redact: {
paths: ['anotherPath'],
censor: 'Not the log you\re looking for'
}
});
anotherRedacted.info({
msg: 'another logged with redacted properties',
anotherPath: 'Not shown'
});