Skip to content

Commit

Permalink
fix: Ensure silent log level is respected with browser.transmit option (
Browse files Browse the repository at this point in the history
  • Loading branch information
SrsDanny authored Oct 15, 2024
1 parent 5bc0a92 commit 84bbd35
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 4 deletions.
8 changes: 4 additions & 4 deletions browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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,
Expand Down
48 changes: 48 additions & 0 deletions test/browser-transmit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})

0 comments on commit 84bbd35

Please sign in to comment.