allow Logger level values outside TRACE..FATAL
This commit is contained in:
parent
e43a1a405f
commit
74a2a1c57d
3 changed files with 78 additions and 4 deletions
|
@ -8,7 +8,11 @@ Known issues:
|
||||||
|
|
||||||
## bunyan 1.2.2 (not yet released)
|
## bunyan 1.2.2 (not yet released)
|
||||||
|
|
||||||
(nothing yet)
|
- Drop the guard that a bunyan Logger level must be between TRACE (10)
|
||||||
|
and FATAL (60), inclusive. This allows a trick of setting the level
|
||||||
|
to `FATAL + 1` to turn logging off. While the standard named log levels are
|
||||||
|
the golden path, then intention was not to get in the way of using
|
||||||
|
other level numbers.
|
||||||
|
|
||||||
|
|
||||||
## bunyan 1.2.1
|
## bunyan 1.2.1
|
||||||
|
|
|
@ -205,9 +205,6 @@ function resolveLevel(nameOrNum) {
|
||||||
var level = (typeof (nameOrNum) === 'string'
|
var level = (typeof (nameOrNum) === 'string'
|
||||||
? levelFromName[nameOrNum.toLowerCase()]
|
? levelFromName[nameOrNum.toLowerCase()]
|
||||||
: nameOrNum);
|
: nameOrNum);
|
||||||
if (! (TRACE <= level && level <= FATAL)) {
|
|
||||||
throw new Error('invalid level: ' + nameOrNum);
|
|
||||||
}
|
|
||||||
return level;
|
return level;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
73
test/level.test.js
Normal file
73
test/level.test.js
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2014 Trent Mick. All rights reserved.
|
||||||
|
*
|
||||||
|
* Test the `log.level(...)`.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var util = require('util'),
|
||||||
|
format = util.format,
|
||||||
|
inspect = util.inspect;
|
||||||
|
var p = console.log;
|
||||||
|
|
||||||
|
var bunyan = require('../lib/bunyan');
|
||||||
|
|
||||||
|
// node-tap API
|
||||||
|
if (require.cache[__dirname + '/tap4nodeunit.js'])
|
||||||
|
delete require.cache[__dirname + '/tap4nodeunit.js'];
|
||||||
|
var tap4nodeunit = require('./tap4nodeunit.js');
|
||||||
|
var after = tap4nodeunit.after;
|
||||||
|
var before = tap4nodeunit.before;
|
||||||
|
var test = tap4nodeunit.test;
|
||||||
|
|
||||||
|
|
||||||
|
// ---- test boolean `log.<level>()` calls
|
||||||
|
|
||||||
|
var log1 = bunyan.createLogger({
|
||||||
|
name: 'log1',
|
||||||
|
streams: [
|
||||||
|
{
|
||||||
|
path: __dirname + '/level.test.log1.log',
|
||||||
|
level: 'info'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
test('log.level() -> level num', function (t) {
|
||||||
|
t.equal(log1.level(), bunyan.INFO);
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('log.level(<const>)', function (t) {
|
||||||
|
log1.level(bunyan.DEBUG);
|
||||||
|
t.equal(log1.level(), bunyan.DEBUG);
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('log.level(<num>)', function (t) {
|
||||||
|
log1.level(10);
|
||||||
|
t.equal(log1.level(), bunyan.TRACE);
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('log.level(<name>)', function (t) {
|
||||||
|
log1.level('error');
|
||||||
|
t.equal(log1.level(), bunyan.ERROR);
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
// A trick to turn logging off.
|
||||||
|
// See <https://github.com/trentm/node-bunyan/pull/148#issuecomment-53232979>.
|
||||||
|
test('log.level(FATAL + 1)', function (t) {
|
||||||
|
log1.level(bunyan.FATAL + 1);
|
||||||
|
t.equal(log1.level(), bunyan.FATAL + 1);
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('log.level(<weird numbers>)', function (t) {
|
||||||
|
log1.level(0);
|
||||||
|
t.equal(log1.level(), 0);
|
||||||
|
log1.level(Number.MAX_VALUE);
|
||||||
|
t.equal(log1.level(), Number.MAX_VALUE);
|
||||||
|
t.end();
|
||||||
|
});
|
Loading…
Reference in a new issue