Handling Exceptions

Winston can handle uncaught exceptions and unhandled rejections.

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: 'combined.log' })
  ],
  exceptionHandlers: [
    new winston.transports.Console(),
    new winston.transports.File({ filename: 'exceptions.log' })
  ]
});

process.on('unhandledRejection', (ex) => {
  throw ex;
});

Comments

Leave a Reply

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