How to flush winston logs?

bevacqua picture bevacqua · Sep 12, 2013 · Viewed 11.4k times · Source

I want to flush the winston logger before process.exit.

process.on('uncaughtException', function(err){
    logger.error('Fatal uncaught exception crashed cluster', err);
    logger.flush(function(){ // <-
        process.exit(1);
    });
});

Is there anything like logger.flush available? I couldn't find anything about it, other than people complaining about winston not being very actively maintained.

As an alternative, is there any popular (actively maintained) multi-transport logging framework that provides a flushing capability?

Answer

Thomas Heymann picture Thomas Heymann · Sep 13, 2013

Winston actually allows you to pass in a callback which is executed when all transports have been logged:

process.on('uncaughtException', function(err) {
    logger.log('error', 'Fatal uncaught exception crashed cluster', err, function(err, level, msg, meta) {
        process.exit(1);
    });
});

Docs: https://github.com/flatiron/winston#events-and-callbacks-in-winston