Skip to content Skip to sidebar Skip to footer

Separate Info And Error Logs Bunyan

As I have seen many logs in blogs and I find bunyan suitable for logging but there is problem with it that it can't log to file according to their level. Below is code structure I

Solution 1:

A log level for a rotating file stream needs to be specified when configuring bunyan.

By default, log output is to stdout and at the "info" level.

Setting a logger instance (or one of its streams) to a particular level implies that all log records at that level and above are logged. E.g. a logger set to level "info" will log records at level info and above (warn, error, fatal).

Error logs are thus also collected to the info log.


Solution 2:

I met the same problem, finally I created 2 variables like:

var debugLog = bunyan.createLogger({
  name: 'general',
  streams: [
    {
      level: 'debug',
      path: './debug.log'
    }]
});

var errLog = bunyan.createLogger({
  name: 'general',
  streams: [
    {
      level: 'error',
      path: './error.log'
    }]
});

debugLog.info('hello world');
errLog.error('error');

Then logs will be in different log files.


Post a Comment for "Separate Info And Error Logs Bunyan"