Answer the question
In order to leave comments, you need to log in
My jamb or winston module?
I am setting up a logger for a chat server on a node. I'm using the winston module.
As you can see in the code below, I explicitly specify the level, but in the log it is still ERROR? How to fix?
var winston = require('winston');
var logger = new (winston.Logger)({
transports: [
// настройки логгирования в консоль
new (winston.transports.Console)({
level: 'info', // тип логирования
timestamp: function() {
return moment().format("DD-MM-YYYY HH:mm:ss.SSS");
},
formatter: function(options) {
return '[TIMESTAMP:' + options.timestamp() +'] [LEVEL:'+ options.level.toUpperCase() +']'+ (undefined !== options.message ? " [MESSAGE:"+options.message+"]" : '') +
(options.meta && Object.keys(options.meta).length ? ' [META:'+ JSON.stringify(options.meta) +']' : '' );
}
}),
// настройки логгирования в файл
new (winston.transports.File)({
filename: './log/logfile_'+moment().format("YYYYMMDD")+'.log',
json: false,
level: 'info', // тип логирования
timestamp: function() {
return moment().format("DD-MM-YYYY HH:mm:ss.SSS");
},
formatter: function(options) {
return '[TIMESTAMP:' + options.timestamp() +'] [LEVEL:'+ options.level.toUpperCase() +']'+ (undefined !== options.message ? " [MESSAGE:"+options.message+"]" : '') +
(options.meta && Object.keys(options.meta).length ? ' [META:'+ JSON.stringify(options.meta) +']' : '' );
}
})
]
});
[TIMESTAMP:14-02-2016 20:32:05.426] [LEVEL:ERROR] [MESSAGE:undefined Сервер чата готов и ждет подключения! Информация - %s:%d]
[TIMESTAMP:14-02-2016 20:32:05.536] [LEVEL:ERROR] [MESSAGE:undefined Подключение к MongoDB '%s' успешно установлено!]
Answer the question
In order to leave comments, you need to log in
options.level which comes in formatter has nothing to do with ' level: 'info', // logging type' has no
logger.error/logger.info/logger.debug - that's it
setting ' level: 'info' skips logger. error and logger.info
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question