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

Fix set level in browser logger #424

Merged
merged 3 commits into from
May 30, 2018
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
12 changes: 6 additions & 6 deletions browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,14 @@ pino.levels = {
pino.stdSerializers = stdSerializers

function set (opts, logger, level, fallback) {
var val = logger.levelVal
logger[level] = val > pino.levels.values[level] ? noop
: (logger[level] ? logger[level] : (_console[level] || _console[fallback] || noop))
var proto = Object.getPrototypeOf(logger)
logger[level] = logger.levelVal > logger.levels.values[level] ? noop
: (proto[level] ? proto[level] : (_console[level] || _console[fallback] || noop))

wrap(opts, logger, logger.val, level)
wrap(opts, logger, level)
}

function wrap (opts, logger, val, level) {
function wrap (opts, logger, level) {
if (!opts.transmit && logger[level] === noop) return

logger[level] = (function (write) {
Expand Down Expand Up @@ -190,7 +190,7 @@ function wrap (opts, logger, val, level) {
transmitLevel: transmitLevel,
transmitValue: pino.levels.values[opts.transmit.level || logger.level],
send: opts.transmit.send,
val: val
val: logger.levelVal
}, args)
}
}
Expand Down
60 changes: 60 additions & 0 deletions test/browser.levels.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,66 @@ test('set the level by string', function (t) {
t.end()
})

test('set the level by string. init with silent', function (t) {
t.plan(4)
var expected = [
{
level: 50,
msg: 'this is an error'
},
{
level: 60,
msg: 'this is fatal'
}
]
var instance = pino({
level: 'silent',
browser: {
write: function (actual) {
checkLogObjects(t, actual, expected.shift())
}
}
})

instance.level = 'error'
instance.info('hello world')
instance.error('this is an error')
instance.fatal('this is fatal')
t.end()
})

test('set the level by string. init with silent and transmit', function (t) {
t.plan(4)
var expected = [
{
level: 50,
msg: 'this is an error'
},
{
level: 60,
msg: 'this is fatal'
}
]
var instance = pino({
level: 'silent',
browser: {
write: function (actual) {
checkLogObjects(t, actual, expected.shift())
}
},
transmit: {
send: function () {
}
}
})

instance.level = 'error'
instance.info('hello world')
instance.error('this is an error')
instance.fatal('this is fatal')
t.end()
})

test('set the level via constructor', function (t) {
t.plan(4)
var expected = [
Expand Down