Search code examples
node.jsloggingnpmwinston

winston - TypeError: winston.createLogger is not a constructor


winston.createLogger(); is apparently not a constructor. Why is this so?

I have seen some people try and roll back to winston@3.0.0, but that doesn't work for me. I am on the latest version of winston. Here is some of logger.js:

const winston = require('winston');

const level = process.env.LOG_LEVEL || 'debug';


let logger = new winston.createLogger({
    transports: [
        new winston.transports.Console({
            level: level,
            timestamp: function() {
                return (new Date()).toISOString();
            }
        })
    ]
});

module.exports = logger;

I expect it to create the logger, but it throws a TypeError telling me that createLogger isn't a constructor!


Solution

  • Do not use new winston.Logger(opts) – it has been removed for improved performance. Use winston.createLogger(opts) instead.

    Check this for reference