From b5c447eadaf0f5fe170f0222ee63bebfd040ad9d Mon Sep 17 00:00:00 2001 From: Theo Ephraim Date: Tue, 10 Dec 2024 16:15:41 -0800 Subject: [PATCH] add types and docs --- docs/api.md | 17 +++++++++++++++++ pino.d.ts | 6 ++++++ pino.js | 3 ++- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/docs/api.md b/docs/api.md index b3d5a0b6a..c68ba5cbd 100644 --- a/docs/api.md +++ b/docs/api.md @@ -375,6 +375,23 @@ const hooks = { } ``` + + +##### `streamWrite` + +Allows for manipulating the _stringified_ JSON log data just before writing to various transports. + +The method receives the stringified JSON and must return valid stringified JSON. + +For example: +```js +const hooks = { + streamWrite (s) { + return s.replaceAll('sensitive-api-key', 'XXX') + } +} +``` + #### `formatters` (Object) diff --git a/pino.d.ts b/pino.d.ts index cdc5958d3..87eebe38d 100644 --- a/pino.d.ts +++ b/pino.d.ts @@ -641,6 +641,12 @@ declare namespace pino { * using apply, like so: method.apply(this, newArgumentsArray). */ logMethod?: (this: Logger, args: Parameters, method: LogFn, level: number) => void; + + /** + * Allows for manipulating the stringified JSON log output just before writing to various transports. + * This function must return a string and must be valid JSON. + */ + streamWrite?: (s: string) => string; }; /** diff --git a/pino.js b/pino.js index 2398e5acb..cabeaf6d6 100644 --- a/pino.js +++ b/pino.js @@ -70,7 +70,8 @@ const defaultOptions = { } }), hooks: { - logMethod: undefined + logMethod: undefined, + streamWrite: undefined }, timestamp: epochTime, name: undefined,