Thursday, 20 October 2022

What exactly is the use of defining level in the top-most scope?

I was just going through the Winston logger usage guide and came across the following usage:

const logger = winston.createLogger({
  level: 'info',
  format: winston.format.json(),
  defaultMeta: { service: 'user-service' },
  transports: [
    //
    // - Write all logs with importance level of `error` or less to `error.log`
    // - Write all logs with importance level of `info` or less to `combined.log`
    //
    new winston.transports.File({ filename: 'error.log', level: 'error' }),
    new winston.transports.File({ filename: 'combined.log' }),
  ],
});

What is the use of defining level: 'info', if you're going to have level: 'error'? Or is it the case that the latter is overriding level: 'info',, because according to the docs the outer level does the following:

Log only if info.level is less than or equal to this level

So what exactly is the use of defining level in the top-most scope?

EDIT :- Also the docs HERE says the following :-

winston allows you to define a level property on each transport which specifies the maximum level of messages that a transport should log. For example, using the syslog levels you could log only error messages to the console and everything info and below to a file.

So based on the above and given that syslog levels are the below:-

{
  emerg: 0,
  alert: 1,
  crit: 2,
  error: 3,
  warning: 4,
  notice: 5,
  info: 6,
  debug: 7
}

so what exactly is 'info' and below ?



from What exactly is the use of defining level in the top-most scope?

No comments:

Post a Comment