How to flush winston logs?
Unfortuantely, Winston will sometimes call the logging callback before the transport has had a chance to flush, so the accepted answer can still lead to un-saved log messages (especially on the first turn of the event loop). A better solution is implemented in the winston-log-and-exit package / patch.
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