From 355650e47924d04b4c7dce9100b74cc6e05cf1f9 Mon Sep 17 00:00:00 2001 From: Dominik Stefanicka Date: Thu, 23 Jun 2022 14:41:07 +0200 Subject: [PATCH] Add the replacer option to the HTTP transport Support custom stringify replacer when sending logs via HTTP transport. Usage of the `format.json` with the custom replacer does not work with HTTP transport since the message symlink (which is mutated) is not sent in the request. --- lib/winston/transports/http.js | 2 +- lib/winston/transports/index.d.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/winston/transports/http.js b/lib/winston/transports/http.js index 66a5df905..bc5ffd8d0 100644 --- a/lib/winston/transports/http.js +++ b/lib/winston/transports/http.js @@ -262,6 +262,6 @@ module.exports = class Http extends TransportStream { req.on('response', res => ( res.on('end', () => callback(null, res)).resume() )); - req.end(Buffer.from(jsonStringify(options), 'utf8')); + req.end(Buffer.from(jsonStringify(options, this.options.replacer), 'utf8')); } }; diff --git a/lib/winston/transports/index.d.ts b/lib/winston/transports/index.d.ts index acedfe415..b8b6c62b8 100644 --- a/lib/winston/transports/index.d.ts +++ b/lib/winston/transports/index.d.ts @@ -62,6 +62,7 @@ declare namespace winston { batch?: boolean; batchInterval?: number; batchCount?: number; + replacer?: (key: string, value: any) => any; } interface HttpTransportInstance extends Transport {