I am trying to use bunyan in my nodejs application, however I stuck with this bizarre behaviour. Defining the logger like so:
var info = bunyan.createLogger({
name: 'Test',
streams: [
{
path: './logger/fatal.log',
level: 'fatal'
},
{
path: './logger/error.log',
level: 'error'
},
{
path: './logger/warn.log',
level: 'warn'
},
{
path: './logger/info.log',
level: 'info'
},
{
path: './logger/debug.log',
level: 'debug'
},
{
path: './logger/trace.log',
level: 'trace'
}
]
});
And I am calling them in a function like so:
var func = function () {
info.fatal("FATAL!");
info.error("ERROR!");
info.warn("WARN!");
info.debug("DEBUG!");
info.info("INFO");
info.trace("TRACE");
}
Now the predictable behaviour would be
fatal.log has {"name":"Test","hostname":"ENIGMA","pid":16793,"level":60,"msg":"FATAL!","time":"2016-01-21T09:12:34.293Z","v":0}
and error.log has {"name":"Test","hostname":"ENIGMA","pid":16793,"level":50,"msg":"ERROR!","time":"2016-01-21T09:12:34.295Z","v":0}
and so forth.
However, on my application,
fatal.log has {"name":"Test","hostname":"ENIGMA","pid":16793,"level":60,"msg":"FATAL!","time":"2016-01-21T09:12:34.293Z","v":0}
error.log has
{"name":"Test","hostname":"ENIGMA","pid":16793,"level":60,"msg":"FATAL!","time":"2016-01-21T09:12:34.293Z","v":0}
{"name":"Test","hostname":"ENIGMA","pid":16793,"level":50,"msg":"ERROR!","time":"2016-01-21T09:12:34.295Z","v":0}
warn.log has
{"name":"Test","hostname":"ENIGMA","pid":16793,"level":60,"msg":"FATAL!","time":"2016-01-21T09:12:34.293Z","v":0}
{"name":"Test","hostname":"ENIGMA","pid":16793,"level":50,"msg":"ERROR!","time":"2016-01-21T09:12:34.295Z","v":0}
{"name":"Test","hostname":"ENIGMA","pid":16793,"level":40,"msg":"WARN!","time":"2016-01-21T09:12:34.296Z","v":0}
and so forth.
The higher level logs are getting into the lower streams. How do I prevent this behaviour and make each level log into its own specific file? (I have also reported an issue at node-bunyan)
This is part of the design of a logger. The higher levels will always get logged into lower levels too. So the last level will be the most verbose of them all.