Dynamic Log Levels

You might need to adjust log levels dynamically, for example, via an environment variable or a configuration file.

const winston = require('winston');

const logLevel = process.env.LOG_LEVEL || 'info';

const logger = winston.createLogger({
  level: logLevel,
  format: winston.format.combine(
    winston.format.timestamp(),
    winston.format.json()
  ),
  transports: [
    new winston.transports.Console()
  ]
});

logger.info('This log level is dynamically set');

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *