diff --git a/browser.js b/browser.js index 522de1a05..7d0aa2ba3 100644 --- a/browser.js +++ b/browser.js @@ -280,8 +280,8 @@ function set (self, opts, rootLogger, level) { if (!opts.transmit) return const transmitLevel = opts.transmit.level || self.level - const transmitValue = rootLogger.levels.values[transmitLevel] - const methodValue = rootLogger.levels.values[level] + const transmitValue = levelToValue(transmitLevel, rootLogger) + const methodValue = levelToValue(level, rootLogger) if (methodValue < transmitValue) return } @@ -322,8 +322,8 @@ function createWrap (self, opts, rootLogger, level) { if (opts.transmit) { const transmitLevel = opts.transmit.level || self._level - const transmitValue = rootLogger.levels.values[transmitLevel] - const methodValue = rootLogger.levels.values[level] + const transmitValue = levelToValue(transmitLevel, rootLogger) + const methodValue = levelToValue(level, rootLogger) if (methodValue < transmitValue) return transmit(this, { ts, diff --git a/test/browser-transmit.test.js b/test/browser-transmit.test.js index 860524ba6..d5063ca8e 100644 --- a/test/browser-transmit.test.js +++ b/test/browser-transmit.test.js @@ -367,3 +367,51 @@ test('does not log below configured level', ({ end, is }) => { end() }) + +test('silent level prevents logging even with transmit', ({ end, fail }) => { + const logger = pino({ + level: 'silent', + browser: { + write () { + fail('no data should be logged by the write method') + }, + transmit: { + send () { + fail('no data should be logged by the send method') + } + } + } + }) + + Object.keys(pino.levels.values).forEach((level) => { + logger[level]('ignored') + }) + + end() +}) + +test('does not call send when transmit.level is set to silent', ({ end, fail, is }) => { + let c = 0 + const logger = pino({ + level: 'trace', + browser: { + write () { + c++ + }, + transmit: { + level: 'silent', + send () { + fail('no data should be logged by the transmit method') + } + } + } + }) + + const levels = Object.keys(pino.levels.values) + levels.forEach((level) => { + logger[level]('message') + }) + + is(c, levels.length, 'write must be called exactly once per level') + end() +})