Closed otisg closed 8 years ago
winston allows transports to handle uncaught exceptions. The Amazon-SNS and Graylog2 transports are examples that handle this. In node, especially, unhandled exception handling is critical because it's not compiled, strongly typed, and exception handling is "hard" to get right. Alerts on uncaught exceptions are almost necessary even with robust unit test coverage.
If winston-logsene handled uncaught exceptions, I wouldn't need to separate those exceptions out to their own log and tail them with logstash.
Big +1. We've been wanting to capture exceptions automatically.
This should work now in 1.0.9:
var winston = require('winston')
var Logsene = require('winston-logsene')
var logger = new winston.Logger()
logger.add(Logsene, {
token: process.env.LOGSENE_TOKEN,
handleExceptions: true,
exitOnError: false})
BTW: Logstash? ;) Check out https://github.com/sematext/logagent-js
Here's a hack to emulate exitOnError:true
var winston = require('winston');
var winstonLogsene = require('winston-logsene');
var logseneInstance;
var logger = new winston.Logger({
transports: [
new winston.transports.Console({
colorize: true,
handleExceptions: false,
}),
logseneInstance = new winstonLogsene({
token: process.env.LOGSENE,
type: process.env.APP || 'api-unkown',
handleExceptions: false
})
]
});
process.on('uncaughtException', function (err) {
logger.error(err.stack || err.toString());
logseneInstance.logger.send(function() {
process.exit(1);
});
});
I think this can be closed.
Feedback from a Logsene user: The winston-logsene transport would benefit from the handlesExceptions option.