bithavoc / express-winston

express.js middleware for winstonjs
https://www.npmjs.com/package/express-winston
MIT License
797 stars 187 forks source link

expressWinston.errorLogger: No logging when using level #150

Closed martinzuern closed 7 years ago

martinzuern commented 7 years ago

When using a function for the level option, nothing will be logged by the error logger. Please find a simple example attached:

  app.use(expressWinston.errorLogger({
    winstonInstance: logger,
    msg: '{{err.message}}',
    level: function() {
      return 'warn';
    }
  }));
rosston commented 7 years ago

I just tested this, and it seems to be working fine. Is it possible that you have your transport(s) on your winstonInstance set not to log at the "warn" level?

Here's the code I used (with some transport options laid out as well):

app.use(expressWinston.errorLogger({
  transports: [
      new winston.transports.Console({}),
      // new winston.transports.Console({level: 'warn'}), // also works
      // new winston.transports.Console({level: 'error'}), // DOES NOT work (reproduces bug)
  ],
  msg: '{{err.message}}',
  level: function() {
    return 'warn';
  }
}));
martinzuern commented 7 years ago

Thanks for your quick response. You're right – sorry for bothering you with this issue.

rosston commented 7 years ago

No problem!