Updated winston to 3.0.0 Got this error when running my nodejs application the following error appears
TypeError: colors[Colorizer.allColors[lookup]] is not a function
If you are adding custom colors to your Winston configuration you can only use colors defined by the colors package. This was the issue I had.
If you are using format.colorize
, you must take care to always indicate the log level.
You can indicate it as the initial parameter, in this case 'error':
logger.log('error', 'hello', { message: 'world' });
You can call its specific method:
logger.error('hello', { message: 'world' });
The problem that you encountered occurs if at any time you omit the level; for example, if you write something like this:
logger.log('hello', { message: 'world' });
Used winstone package: version 3.8.0
If you are using colorize() from Winstone package, and you created a custom level, you must define a color for this level.
Winston is using logform package for supplying default colors. The crash will occur in colorize.js file inside logform package:
colorize.js:
if (!Array.isArray(Colorizer.allColors[lookup])) {
return colors[Colorizer.allColors[lookup]](message);
}
'lookup' variable will be undefined if you won't define a color for your custom level.
Notice how I define a color for 'request' level
import { config, addColors } from 'winston';
// Adding a custom level named 'request'
const levels = { ...config.syslog.levels, request: 6.5 };
// Configuring 'request' color
addColors({ ...config.syslog.colors, request: config.syslog.colors.debug });
(Notice there is a "request" color - it got added)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With