3

Cant get any colors in console from Winston logger v3.x

const winston = require('winston')
const logLevels = {
  levels: {
    emerg: 0,
    alert: 1,
    crit: 2,
    error: 3,
    warning: 4,
    notice: 5,
    info: 6,
    debug: 7
  },
  colors: {
    emerg: 'red',
    alert: 'red',
    crit: 'red',
    error: 'red',
    warning: 'yellow',
    notice: 'blue',
    info: 'green',
    debug: 'green'
  }
}
winston.addColors(logLevels)
const logger = winston.createLogger({
  levels: logLevels.levels,
  transports: [
    new winston.transports.Console({
      format: winston.format.simple(),
      colorize: true
    })
  ]
});
logger.info('server starting...', {date: new Date()})

Did this snippet according to documentation on github page https://github.com/winstonjs/winston

No colors though

Vlad Ankudinov
  • 1,936
  • 1
  • 14
  • 22

2 Answers2

3

try to use combine method to format:

 winston.format.combine(
      winston.format.colorize(),
      winston.format.simple()
    );

The colorize formatter must come before any formatters adding text you wish to color. hope it helps. reference

imdzeeshan
  • 1,098
  • 20
  • 26
0

Im not sure but I believe winston.addColors(logLevels) should be winston.addColors(logLevels.colors)

Zachary
  • 26
  • 2