Winston logger.info is not a function

starleaf1 picture starleaf1 · Apr 3, 2017 · Viewed 7.9k times · Source

I've set up Winston with transports to MySQL and console and put it in a module called logger. Like so...

// modules/logger.js

/* require statements */

exports.logger = new (winston.Logger)({
    transports: [
        new winstonMysql(winstonMysqlConfig),
        new (winston.transports.Console)
    ]
});

And then in /modules

// modules/index.js

/* grab other modules */

exports.logger = require('./logger.js');

When I do console.log(modules.logger), I get this

{ logger: 
    EventEmitter {
        ...
        error: [Function],
        warn: [Function],
        info: [Function],
        verbose: [Function],
        debug: [Function],
        silly: [Function],
        ...
    }
 }

But when I call modules.logger.info() it throws modules.logger.info is not a function error. What's wrong?

Answer

Mukesh Sharma picture Mukesh Sharma · Apr 3, 2017

You aren't exporting the logger properly in modules.js.

exports.logger = require('./logger.js').logger;