Reputation: 2719
I added Winston logger to my JS application and all the logs work but not the warning. I have no idea why.
The error every time I try to use .warn(warning)
as
TypeError: _logger.default.warn is not a function
My logger was done in this helper utility
import { config, createLogger, format, transports } from 'winston';
const { printf, combine, timestamp, colorize } = format;
// don't show console logs in test mode
const transport =
process.env.NODE_ENV !== 'test' ? [new transports.Console()] : [];
export default createLogger({
levels: config.syslog.levels,
level: 'info',
format: combine(
timestamp(),
printf((info) => `[${info.timestamp}][${info.level}]: ${info.message}`),
colorize({ all: true })
),
transports: [
...transport,
new transports.File({ filename: 'logs/error.log', level: 'error' }),
new transports.File({ filename: 'logs/application.log' }),
],
});
and I used just under an if statement
if ( validation === 'false' ) {
log.warn('Twilio validation is not active!'); // Here the error occur
return next();
}
I tried to google online but as per documentation should work so I don't know what's wrong as it is the only log not working.
Upvotes: 1
Views: 1549
Reputation: 2412
createLogger()
creates the log level methods based on the levels
object in the options. In config.syslog.levels
the level is called warning
not warn
.
So the method to call should be: log.warning('Twilio validation is not active!');
There is an open issue requesting to implement warn()
as a convenient method for syslog warning level.
Upvotes: 1