sematext / winston-logsene

Winston Transport for Logsene
http://sematext.com/logsene
Apache License 2.0
13 stars 6 forks source link

Add support for handlesExceptions option #3

Closed otisg closed 8 years ago

otisg commented 8 years ago

Feedback from a Logsene user: The winston-logsene transport would benefit from the handlesExceptions option.

rsteckler commented 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.

otisg commented 8 years ago

Big +1. We've been wanting to capture exceptions automatically.

megastef commented 8 years ago

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

johnpeb commented 8 years ago

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);  
  });
});
megastef commented 8 years ago

I think this can be closed.