Allen Hartwig
Allen Hartwig

Reputation: 253

How do you add multiple levels to a single transport in Winston?

How does one tell Winston to log multiple levels to a single transport? For example, if you want to log both info and error level items to the console, how would you accomplish this? Specifying info does not log all levels that are info level and more critical, it just logs info. Passing an array of levels to the level property does nothing.

winston.add(winston.transports.Console, {
    colorize: true,
    level: 'info'
});

or

winston.add(winstonMongo, {
    safe: false,
    db: 'logs',
    collection: 'api',
    level: 'info'
});

Upvotes: 9

Views: 6063

Answers (2)

makenova
makenova

Reputation: 3645

For posterity, I've included a code snippet from the winston source code detailing the default log levels. As mentioned in other answers, specifying a lower log level will log the levels above e.g. specifying silly will log all other levels while specifying debug will log all but silly.

npmConfig.levels = {
  silly: 0,
  debug: 1,
  verbose: 2,
  info: 3,
  warn: 4,
  error: 5
};

According to the winston readme this is the "npm" style but the npm document it links to has different log levels.

Upvotes: 4

Allen Hartwig
Allen Hartwig

Reputation: 253

Specifying the info level does include all levels that are more severe (eg: warn, error, debug). Likewise, specifying warn includes the warn level, plus the more severe error level.

Upvotes: 11

Related Questions