From d01d5284b975179bed337b867e9924ee4366cb0a Mon Sep 17 00:00:00 2001 From: benib Date: Sun, 26 Nov 2017 02:15:22 +0100 Subject: [PATCH 1/4] apply default serializer.req before using configured serializer.req to make this work with pino-noir redacting values below req (BC breaking) --- index.js | 9 ++++++++- test.js | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 1d76f4b..1e22656 100644 --- a/index.js +++ b/index.js @@ -14,7 +14,14 @@ const levelTags = { async function register (server, options) { options.serializers = options.serializers || {} - options.serializers.req = options.serializers.req || asReqValue + if (options.serializers.req) { + const oriqReqSerializer = options.serializers.req + options.serializers.req = (req) => { + return oriqReqSerializer(asReqValue(req)) + } + } else { + options.serializers.req = asReqValue + } options.serializers.res = options.serializers.res || pino.stdSerializers.res options.serializers.err = options.serializers.err || pino.stdSerializers.err diff --git a/test.js b/test.js index 422af45..b54286b 100644 --- a/test.js +++ b/test.js @@ -742,7 +742,7 @@ experiment('logging with overridden serializer', () => { options: { instance: logger, serializers: { - req: (req) => ({ uri: req.raw.req.url }) + req: (req) => ({ uri: req.url }) } } } From 1fc78ce405198c5ea5df8ebd6b8866477bbc1f6b Mon Sep 17 00:00:00 2001 From: benib Date: Sun, 26 Nov 2017 02:23:09 +0100 Subject: [PATCH 2/4] do not apply any req serializer if options.serializer.req is set to null --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 1e22656..0cbb32d 100644 --- a/index.js +++ b/index.js @@ -19,7 +19,7 @@ async function register (server, options) { options.serializers.req = (req) => { return oriqReqSerializer(asReqValue(req)) } - } else { + } else if (options.serializers.req !== null) { options.serializers.req = asReqValue } options.serializers.res = options.serializers.res || pino.stdSerializers.res From e4c3ece202628c7a9f002d7e76d23ead4d8fea9e Mon Sep 17 00:00:00 2001 From: benib Date: Sun, 26 Nov 2017 22:11:06 +0100 Subject: [PATCH 3/4] add a test case with serializer.req set to null --- test.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test.js b/test.js index b54286b..f90bc43 100644 --- a/test.js +++ b/test.js @@ -755,6 +755,36 @@ experiment('logging with overridden serializer', () => { await finish }) + test('with req serializer set to null', async () => { + const server = getServer() + let done + const finish = new Promise(function (resolve, reject) { + done = resolve + }) + const stream = sink((data) => { + expect(data.req.uri).to.not.equal('/') + expect(data.req.raw).to.be.an.object() + done() + }) + const logger = require('pino')(stream) + const plugin = { + plugin: Pino, + options: { + instance: logger, + serializers: { + req: null + } + } + } + + await server.register(plugin) + await server.inject({ + method: 'GET', + url: '/' + }) + await finish + }) + test('with pre-defined res serializer', async () => { const server = getServer() let done From d5fdeef1aa5c0535ae25b92d2a2d538883e1e498 Mon Sep 17 00:00:00 2001 From: benib Date: Mon, 27 Nov 2017 16:51:15 +0100 Subject: [PATCH 4/4] fix typo --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 0cbb32d..a2af573 100644 --- a/index.js +++ b/index.js @@ -15,9 +15,9 @@ const levelTags = { async function register (server, options) { options.serializers = options.serializers || {} if (options.serializers.req) { - const oriqReqSerializer = options.serializers.req + const origReqSerializer = options.serializers.req options.serializers.req = (req) => { - return oriqReqSerializer(asReqValue(req)) + return origReqSerializer(asReqValue(req)) } } else if (options.serializers.req !== null) { options.serializers.req = asReqValue