Skip to content

Commit

Permalink
fix(browser): should respect log level with transmit (#2005)
Browse files Browse the repository at this point in the history
Co-authored-by: Anastasiia Dragich <anastasiia.dragich@booking.com>
  • Loading branch information
adragich and Anastasiia Dragich committed Jul 12, 2024
1 parent 859d6d5 commit b5f5cbc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
9 changes: 7 additions & 2 deletions browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,13 @@ function set (self, opts, rootLogger, level) {
configurable: true
})

if (!opts.transmit && self[level] === noop) {
return
if (self[level] === noop) {
if (!opts.transmit) return

const transmitLevel = opts.transmit.level || self.level
const transmitValue = rootLogger.levels.values[transmitLevel]
const methodValue = rootLogger.levels.values[level]
if (methodValue < transmitValue) return
}

// make sure the log format is correct
Expand Down
20 changes: 20 additions & 0 deletions test/browser-transmit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,3 +347,23 @@ test('extracts correct bindings and raw messages over multiple transmits', ({ en

end()
})

test('does not log below configured level', ({ end, is }) => {
let message = null
const logger = pino({
level: 'info',
browser: {
write (o) {
message = o.msg
},
transmit: {
send () { }
}
}
})

logger.debug('this message is silent')
is(message, null)

end()
})

0 comments on commit b5f5cbc

Please sign in to comment.