Multiple log paths in bunyan

I'm using Bunyan with Restify to create an access.log which will store information about requests such as the endpoint, status-code etc... However, I'd like to separate the errors from this file and store them in a separate log-file.

I've tried creating the second error logger by adding an additional stream to the Bunyan logger instance, however errors aren't being written to error log-file. Any ideas why that is?

var log = new Logger({
  name: 'logga',
  streams: [
    {
      stream: process.stdout,
      level: 'debug'
    },
    {
      path: './logs/access.log',
      level: 'trace'
    },
    {
      path: './logs/error.log',
      level: 'error'
    }
  ],
  serializers: Logger.stdSerializers
});

server.on('uncaughtException', function (request, response, route, error) {
  log.error(error);
});

You can remove serializers: Logger.stdSerializers. That should fix it.

If the only log.error(error); call is in your uncaughtException handler, then most probably the error stream isn't being flushed before your process exits due to the uncaught exception. You can try logging an error somewhere else to confirm that.