chris-rock / bunyan-logstash-tcp

logstash tcp module for bunyan
21 stars 21 forks source link

NodeJs application crashes when logstash server is not reachable #16

Closed shah-dhara closed 9 years ago

shah-dhara commented 9 years ago

NodeJS application crashes with following error when the logstash server is not reachable:

ERROR

events.js:72 throw er; // Unhandled 'error' event ^ Error: connect ECONNREFUSED at errnoException (net.js:904:11) at Object.afterConnect as oncomplete

Can you please help me to solve this?

shah-dhara commented 9 years ago

I figured out the problem, I didn't handle 'error' event on bunyan tcp stream. It is there in an example, but was not mentioned in the documentation.

chris-rock commented 9 years ago

@shah-dhara Could you post an example or test case? This would help us to catch this error in bunyan-logstash-tcp

shah-dhara commented 9 years ago

Sure, error came up as for setting up the stream I wrote the following code

stream: bunyantcp.createStream({
        host: '127.0.0.1',
        port: 9998
    })

This was not able to emit the logstash down error and made my NodeJS application crash. I just changed the code to the following:

stream: bunyantcp.createStream({
        host: '127.0.0.1',
        port: 9998
    }).on('error', console.log)