How to set log level in Winston/Node.js

If you are using the default logger, you can adjust the log levels like this:

const winston = require('winston');
// ...
winston.level="debug";

will set the log level to ‘debug’. (Tested with winston 0.7.3, default logger is still around in 3.2.1).

However, the documentation recommends creating a new logger with the appropriate log levels and then using that logger:

const myLogger = winston.createLogger({
  level: 'debug'
});
myLogger.debug('hello world');

If you are already using the default logger in your code base this may require you to replace all usages with this new logger that you are using:

const winston = require('winston');
// default logger
winston.log('debug', 'default logger being used');

// custom logger
myLogger.log('debug', 'custom logger being used');

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)