2012-02-06 23:04:47 +00:00
|
|
|
// Play with setting levels.
|
|
|
|
//
|
|
|
|
// TODO: put this in a damn test suite
|
|
|
|
|
|
|
|
var Logger = require('../lib/bunyan'),
|
2013-03-29 00:42:32 +00:00
|
|
|
DEBUG = Logger.DEBUG,
|
|
|
|
INFO = Logger.INFO,
|
|
|
|
WARN = Logger.WARN;
|
2012-02-06 23:04:47 +00:00
|
|
|
var assert = require('assert');
|
|
|
|
|
|
|
|
// Basic usage.
|
|
|
|
var log = new Logger({
|
2013-03-29 00:42:32 +00:00
|
|
|
name: 'example-level',
|
|
|
|
streams: [
|
|
|
|
{
|
|
|
|
name: 'stdout',
|
|
|
|
stream: process.stdout,
|
|
|
|
level: 'debug'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'stderr',
|
|
|
|
stream: process.stderr
|
|
|
|
}
|
|
|
|
]
|
2012-02-06 23:04:47 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
assert.equal(log.level(), DEBUG);
|
|
|
|
assert.equal(log.levels()[0], DEBUG);
|
|
|
|
assert.equal(log.levels()[1], INFO);
|
|
|
|
assert.equal(log.levels(0), DEBUG);
|
|
|
|
assert.equal(log.levels(1), INFO);
|
|
|
|
|
|
|
|
assert.equal(log.levels('stdout'), DEBUG)
|
|
|
|
try {
|
2013-03-29 00:42:32 +00:00
|
|
|
log.levels('foo')
|
2012-02-06 23:04:47 +00:00
|
|
|
} catch (e) {
|
2013-03-29 00:42:32 +00:00
|
|
|
assert.ok(e.message.indexOf('name') !== -1)
|
2012-02-06 23:04:47 +00:00
|
|
|
}
|
|
|
|
|
2012-06-05 06:19:39 +00:00
|
|
|
log.trace('no one should see this')
|
|
|
|
log.debug('should see this once (on stdout)')
|
|
|
|
log.info('should see this twice')
|
2012-02-06 23:04:47 +00:00
|
|
|
log.levels('stdout', INFO)
|
2012-06-05 06:19:39 +00:00
|
|
|
log.debug('no one should see this either')
|
2012-02-06 23:04:47 +00:00
|
|
|
log.level('trace')
|
|
|
|
log.trace('should see this twice as 4th and 5th emitted log messages')
|