sematext / winston-logsene

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

Does not send successfully unless I wait 30 seconds #11

Closed countergram closed 8 years ago

countergram commented 8 years ago

I just started trying to use the example code with my test Logsene instance. Flush on exit does not appear to be working. So far the only way I've been able to get a log message to be sent in a barebones Node script is to add a 30-second timeout after the log (after reading through the source and seeing the periodic send call). I also read issue #10 and tried the workaround there with the dummy console transport, and have not been successful.

Based on my console.logs, send() of the underlying Logsene object is getting called on exit, but the callback from the http request never executes.

I have winston-logsene 1.2.0, winston 2.2.0, node 6.6.0. Thanks.

(To try to simplify the issue I went a layer down. The following works consistently.)

var Logsene = require('logsene-js');
var logger = new Logsene(process.env.LOGSENE_TOKEN);

logger.log('info', 'exit hook');

process.on('beforeExit', function () {
  if (logger.logCount) {
    logger.send();
  }
});
megastef commented 8 years ago

Did you set options.flushOnExit=true in the winston constructor?

countergram commented 8 years ago

I tried setting flushOnExit: true in the add call and have now tried it on the Winston constructor as well. No change. It defaults to true, and in fact I don't think it can be set to false:

if (!options.flushOnExit) {
    options.flushOnExit = true
}
megastef commented 8 years ago

Please let me know, how to reproduce it. How is your program terminated? Calling process.exit (which means no async code can be executed)?

Could you please post the output of npm ls - so we can check dependencies?

Here is what I did: 1) Run the example https://github.com/sematext/winston-logsene/blob/master/example/index.js `node exaple/index.js`` Output:

node example/index.js 
2016-09-25T17:58:36.327Z winston-logsene: start flushing 1 logs before exit ...
2016-09-25T17:58:36.788Z winston-logssene: flush before exit: 1 logs send.
2016-09-25T17:58:36.989Z winston-logsene: flush: no logs in buffer

Check logs in Logsene:

bildschirmfoto 2016-09-25 um 20 04 16

and Kibana bildschirmfoto 2016-09-25 um 20 03 00

megastef commented 8 years ago

Should be fixed, something changed in logsene-js log counts, and winston-logsene should watch own logCounts. https://github.com/sematext/winston-logsene/commit/3a967abec30b5e4dfd7e53dc40e435ace5e8d338

Even with latest logsene-js, it works again:

node example/index.js 
2016-09-25T19:04:08.075Z winston-logsene: start flushing 1 logs before exit ...
2016-09-25T19:04:08.568Z winston-logssene: flush before exit: 1 logs send.
2016-09-25T19:04:08.771Z winston-logsene: flush: no logs in buffer
countergram commented 8 years ago

I tried with 1.2.1 and it works for me now. Thanks.