我正在使用node-bunyan和 bunyan-logstash-tcp在我的nodejs应用程序中将日志发送到logstash(1.4.2)和elasticsearch(1.4.2)。
每当logstash服务器断开连接或无法访问时,我的nodejs应用程序就会崩溃,并出现以下错误
ERROR
-------
events.js:72
throw er; // Unhandled 'error' event
^
Error: connect ECONNREFUSED
at errnoException (net.js:904:11)
at Object.afterConnect [as oncomplete] (net.js:895:19)
bunyan-logstash-tcp 实际上应该处理这个错误。 谁能帮我解决这个nodejs崩溃问题。
最佳答案
我能够解决这个问题。 创建 TCP Bunyan 流时需要处理错误事件
stream: bunyantcp.createStream({
host: '127.0.0.1',
port: 9998
}).on('error', console.log)
bunyan-logstash-tcp中没有提到这一点文档,但存在于示例代码中。
更新:示例配置
this.log = bunyan.createLogger({
name: name,
streams: [
{
level: 'error',
type: 'raw',
serializers: bunyan.stdSerializers,
stream: bunyantcp.createStream({
application: process.title,
max_connect_retries: 10, // Don't give up on reconnecting
retry_interval: 1000 * 60 // Wait 1s between reconnect attempts
}).on('error', console.log)
}
],
level: 'debug'
});
关于node.js - 当logstash服务器断开连接时,nodejs中出现ECONNREFUSED错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30389014/