Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use boolean flag to ensure serializers are applied once #1976

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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])
Expand Down Expand Up @@ -376,20 +378,22 @@ 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
const methodValue = opts.methodValue
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) {
Expand Down
22 changes: 22 additions & 0 deletions test/browser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down