如何冲洗温斯顿日志?

bev*_*qua 17 node.js winston

我要刷新温斯顿记录仪前 process.exit.

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

有没有logger.flush可用的东西?除了人们抱怨温斯顿没有得到非常积极的维护之外,我找不到任何关于它的信息.

作为替代方案,是否有任何流行的(主动维护的)多传输日志框架提供刷新功能?

Tho*_*ann 11

Winston实际上允许您传入一个回调,该回调在记录所有传输时执行:

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

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

  • 正确,这让我等待''致命异常''消息,如果我想要冲洗所有这些消息怎么办?也许正在记录其他一些消息,并且它正在使用需要更长时间才能完成的传输. (2认同)
  • 没有任何东西不会被冲洗掉。默认的 winston FileTransport 仅在第一次尝试打开底层文件时缓冲日志。https://github.com/flatiron/winston/blob/master/lib/winston/transports/file.js#L134-L142 否则,如果数据没有立即写入底层文件描述符,我们将等待“drain”事件: https://github.com/flatiron/winston/blob/master/lib/winston/transports/file.js#L158-L176 (2认同)