Search code examples
node.jsloggingwinston

Winston event logging - can't add listener to default logger


I am using winston to log on nodejs and I am configuring the global logger to be used in my project. When I try to attach event handlers to the default logger, I run into problems.

winston.on('logging', function (transport, level, msg, meta) {
  console.log('logged');
});

This gives me the error: TypeError: winston.on is not a function

Any ideas of how to do this?


Solution

  • this method should be used on a winstom instance like

    var logger = new (winston.Logger);
    
    logger.on('logging', function (transport, level, msg, meta) {
       console.log('logged');
    });