diff --git a/browser.js b/browser.js index f786739ae..a27cd231b 100644 --- a/browser.js +++ b/browser.js @@ -302,8 +302,10 @@ function createWrap (self, opts, rootLogger, level) { const proto = (Object.getPrototypeOf && Object.getPrototypeOf(this) === _console) ? _console : this for (var i = 0; i < args.length; i++) args[i] = arguments[i] - if (opts.serialize && !opts.transmit) { + var argsIsSerialized = false + if (opts.serialize) { applySerializers(args, this._serialize, this.serializers, this._stdErrSerialize) + argsIsSerialized = true } if (opts.asObject || opts.formatters) { write.call(proto, asObject(this, level, args, ts, opts.formatters)) @@ -322,7 +324,7 @@ function createWrap (self, opts, rootLogger, level) { transmitValue: rootLogger.levels.values[opts.transmit.level || self._level], send: opts.transmit.send, val: levelToValue(self._level, rootLogger) - }, args) + }, args, argsIsSerialized) } } })(self[baseLogFunctionSymbol][level]) @@ -376,7 +378,7 @@ function applySerializers (args, serialize, serializers, stdErrSerialize) { } } -function transmit (logger, opts, args) { +function transmit (logger, opts, args, argsIsSerialized = false) { const send = opts.send const ts = opts.ts const methodLevel = opts.methodLevel @@ -384,12 +386,14 @@ function transmit (logger, opts, args) { const val = opts.val const bindings = logger._logEvent.bindings - applySerializers( - args, - logger._serialize || Object.keys(logger.serializers), - logger.serializers, - logger._stdErrSerialize === undefined ? true : logger._stdErrSerialize - ) + if (!argsIsSerialized) { + applySerializers( + args, + logger._serialize || Object.keys(logger.serializers), + logger.serializers, + logger._stdErrSerialize === undefined ? true : logger._stdErrSerialize + ) + } logger._logEvent.ts = ts logger._logEvent.messages = args.filter(function (arg) { diff --git a/test/browser.test.js b/test/browser.test.js index ab0b0450c..f2bb9b318 100644 --- a/test/browser.test.js +++ b/test/browser.test.js @@ -255,6 +255,28 @@ test('opts.browser.serialize and opts.asObject only serializes log data once', ( end() }) +test('opts.browser.serialize, opts.asObject and opts.browser.transmit only serializes log data once', ({ end, ok, is }) => { + const instance = require('../browser')({ + serializers: { + extras (data) { + return { serializedExtras: data } + } + }, + browser: { + serialize: ['extras'], + asObject: true, + transmit: { + send (level, o) { + is(o.messages[0].extras.serializedExtras, 'world') + } + } + } + }) + + instance.info({ extras: 'world' }, 'test') + end() +}) + test('opts.browser.write func log single string', ({ end, ok, is }) => { const instance = pino({ browser: {