I am using winston 3 logger and I want to customize colors. I am using below code:
winston.addColors( {
info: 'green',
error: 'red',
warn: 'yellow',
debug: 'cyan'
});
When I use other colors like brown, pink or hex-codes like #2E6E3E etc., I am getting error:
.../node_modules/winston/lib/winston/logger.js:307
throw ex;
^
TypeError: colors[Colorizer.allColors[lookup]] is not a function
at Colorizer.colorize (.../node_modules/logform/colorize.js:73:49)
Is there a list of allowed colors in Winston? If so, please provide that list.
In addition to the predefined npm, syslog, and cli levels available in winston, you can also choose to define your own:
const myCustomLevels = {
levels: {
foo: 0,
bar: 1,
baz: 2,
foobar: 3
},
colors: {
foo: 'blue',
bar: 'green',
baz: 'yellow',
foobar: 'red'
}
};
const customLevelLogger = winston.createLogger({
levels: myCustomLevels.levels
});
customLevelLogger.foobar('some foobar level-ed message');
Although there is slight repetition in this data structure, it enables simple encapsulation if you do not want to have colors. If you do wish to have colors, in addition to passing the levels to the Logger itself, you must make winston aware of them:
winston.addColors(myCustomLevels.colors);
This enables loggers using the colorize formatter to appropriately color and style the output of custom levels.
Additionally, you can also change background color and font style. For example,
baz: 'italic yellow',
foobar: 'bold red cyanBG'
Possible options are below.
Font styles: bold, dim, italic, underline, inverse, hidden, strikethrough.
Font foreground colors: black, red, green, yellow, blue, magenta,
cyan, white, gray, grey.
Background colors: blackBG, redBG, greenBG, yellowBG, blueBG
magentaBG, cyanBG, whiteBG
These are the only possible options for colors provided by winston. Please check the documentation for winston.