mhart / gelf-stream

A node.js stream to send JS objects to a Graylog2 server (in GELF format)
Other
29 stars 13 forks source link

Implement standard stream.Writeable interface for write/end #6

Closed milas closed 9 years ago

milas commented 9 years ago

Implementations of stream.Writeable.write() and stream.Writeable.end() are supposed to take optional encoding and callbacks. (In the case of end(), the chunk itself is also optional.)

Adding a callback also increases reliability in the case that a message is sent as the stream is closed because it will wait to close the underlying gelfling client until the message is actually written.

This is useful so that the stream can be passed to other libraries that might take advantage of such features. For example, as a workaround to trentm/node-bunyan#37, my .on('uncaughtException') handler logs the exception with Bunyan, then calls .end() on all the streams in Bunyan with callbacks so that it can detect when all loggers have finished and exit the process as soon as they're done.

milas commented 9 years ago

Actually, I realized a better solution for this that's more reliable is to extend the stream.Writable class instead of implementing "on top" of it. Closing this -- I will open a different PR with that change instead.