Log Filtering

To filter logs based on criteria, you can use custom log formats or transports.

const winston = require('winston');

const filterTransport = new winston.transports.Console({
  format: winston.format((info) => {
    if (info.level === 'error') {
      return info;
    }
  })()
});

const logger = winston.createLogger({
  level: 'info',
  format: winston.format.combine(
    winston.format.timestamp(),
    winston.format.json()
  ),
  transports: [filterTransport]
});

logger.info('This will not appear');
logger.error('This is an error message');

Comments

Leave a Reply

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