Reputation: 3228
What is the simplest way to enable default colors logs messages in winston?
For example, if I use winston as follows:
let winston = require('winston')
winston.info('Info message')
winston.error('Error message')
I expect that the colors of info
and error
message will be respectively yellow and red?
Upvotes: 0
Views: 107
Reputation: 406
You can use the colorize
function like so:
const { createLogger, format, transports } = require("winston");
const logger = createLogger({
format: format.colorize({ all: true }),
transports: [new transports.Console()],
})
This will add the standard winston colors for each of the log levels.
If you want to define your own colors, then its
const { createLogger, format, transports, addColors } = require("winston");
addColors({
info: "green", // fontStyle color
warn: "bold yellow",
error: "bold red",
debug: "bold red cyanBG”, //font style, font color, background color
});
const logger = createLogger({
level: “debug”,
format: format.colorize({all: true}),
transports: [new transports.Console()]
})
And then you just export the module and use it everywhere
Upvotes: 0
Reputation: 7575
Even though info
won't be yellow I would suggest you use winston-color
:
const logger = require( 'winston-color' );
logger.info( 'Info message' ); // Will print info in green
logger.error( 'Error message' ); // Will print error in red
Upvotes: 1