A
A
Alexey Yarkov2016-02-14 20:50:53
Node.js
Alexey Yarkov, 2016-02-14 20:50:53

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) +']' : '' );
      }
    })
  ]
});

Result:
[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' успешно установлено!]

And where does undefined come from before the text of the message, I also xs (((

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem Kustikov, 2016-02-20
@art1z

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 question

Ask a Question

731 491 924 answers to any question