diff --git a/browser.js b/browser.js index 97dcb49d9..a3f1cca9a 100644 --- a/browser.js +++ b/browser.js @@ -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) { @@ -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) } } diff --git a/test/browser.levels.test.js b/test/browser.levels.test.js index 27f5efc6a..d63575ded 100644 --- a/test/browser.levels.test.js +++ b/test/browser.levels.test.js @@ -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 = [