Multiple Transports

You can send logs to multiple destinations. For example, you might want to log errors to a file and info messages to the console.

const logger = winston.createLogger({
  level: 'info',
  format: winston.format.combine(
    winston.format.timestamp(),
    winston.format.json()
  ),
  transports: [
    new winston.transports.Console(),
    new winston.transports.File({ filename: 'error.log', level: 'error' }),
    new winston.transports.File({ filename: 'combined.log' })
  ]
});

Comments

Leave a Reply

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