bunyan-cloudwatch
bunyan-cloudwatch copied to clipboard
Logging error handling
It seems that now to handle errors during logging we need to define an onError
function for the stream object.
IMO, it should provide a default onError
function that swallow errors, since logging should never make your application to crash, which is the current behavior if you haven't defined this function.
Also, maybe since the stream inherits from Writeable, error handling should be performed by using a stream.on('error', function(err) {...})
instead of using this onError
function. Or otherwise, we could pass the error function as part of the options. It doesn't feel right to have to define that function directly over the stream.
Opinions?
+1 on using stream.on('error', (err) => {...})
README.md states this is a Writable stream, so this module should implement that interface instead of defining its own. Additionally onError
is not documented in the README.md.
I just got a crash for lack of connectivity too. Logging should not kill servers.
This just happened to us as well when we hit a ThrottlingException. We ended up needing to wrap the logging calls in a domain to avoid the error from blowing up the Express web server. There needs to be a documented best practice and examples on how to handled these types of errors.