I just started using winstonJS for NodeJS app logging.
My code goes like this :
var winston = require('winston');
var logger = new winston.Logger({
levels: { error: 0, warn: 1, info: 2, debug: 3, trace: 4 },
transports: [
new (winston.transports.Console)()
]
});
logger.log('error', 'log0');
logger.log('warn', 'log1');
logger.log('info', 'log2');
logger.log('debug', 'log3');
logger.log('trace', 'log4');
and the ONLY logs that I get in my console are :
info: log2
trace: log4
debug: log3
Note the wrong order as well.
Am I missing something obvious ?
Thanks
You have to consider 2 things:
Also consider that the default logging levels for winston are: silly=0, debug=1, verbose=2, info=3, warn=4, error=5
Analyzing your code I can see you defined a new "info" level, with value of 2: this means the console log will print only messages with levels >= 2, and in your example these levels are exactly info, debug and trace (I guess you define your levels in the wrong order). If you change your code like this, you will see all the message printed:
transports: [
new (winston.transports.Console)({level: 'error'})
]
About the wrong output order I can't reproduce it, my output is always
info: log2
debug: log3
trace: log4
PS: if you define levels like this error: 0, warn: 1, infoz: 2, debug: 3, trace: 4
with anything different replacing info
, the logger will print nothing at all because the default console transport level will remain info
. You can discover your transport level with a simple
console.log(logger.transports.console.level);