From c3bb846fcd1a179e0d7bce1073ccdcb41c8536c0 Mon Sep 17 00:00:00 2001 From: Alexandre Ferrando Date: Sun, 18 Nov 2018 18:58:17 +0100 Subject: [PATCH] Add redact to pino options --- types/pino/index.d.ts | 20 ++++++++++++++++++++ types/pino/pino-tests.ts | 21 +++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/types/pino/index.d.ts b/types/pino/index.d.ts index fed6c45253..bea9987832 100644 --- a/types/pino/index.d.ts +++ b/types/pino/index.d.ts @@ -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; + } } diff --git a/types/pino/pino-tests.ts b/types/pino/pino-tests.ts index c85f2f6873..d3203b5dd4 100644 --- a/types/pino/pino-tests.ts +++ b/types/pino/pino-tests.ts @@ -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' +});