From e4be2e80921142e003526c78b38afeadaf1befa5 Mon Sep 17 00:00:00 2001 From: megastef Date: Fri, 29 Jul 2016 09:09:37 +0200 Subject: [PATCH] fix terminate after log flush --- lib/index.js | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/lib/index.js b/lib/index.js index 779f857..cc7daec 100644 --- a/lib/index.js +++ b/lib/index.js @@ -6,7 +6,7 @@ var common = require('winston/lib/winston/common') var _dirname = require('path').dirname var LogseneJS = require('logsene-js') var flat = require('flat') - +var exitCode = 0 var Logsene = function (options) { Transport.call(this, options) options = options || {} @@ -49,13 +49,23 @@ var Logsene = function (options) { self.emit('flush', data) }) var logseneExitHandler = function (code) { - this.logger.once('log', function () { - process.exit(code) - }) - this.logger.once('error', function () { - process.exit(code) - }) - this.logger.send() + // console.log('exit in winston') + if (this.logger.logCount == 0) { + setTimeout(process.exit, 200) + } else { + this.logger.once('log', function (data) { + // console.log('winston-logssene, flush on exit: ' + data.count) + setTimeout(process.exit, 200) + }) + this.logger.once('error', function () { + setTimeout(process.exit, 200) + }) + this.logger.send() + // when no error or successful "log" event was received, + // the process should terminate. + // upstart waits max 10 seconds before kill -9 + setTimeout(process.exit, 9000) + } }.bind(this) if (options.flushOnExit) { process.once('SIGTERM', logseneExitHandler)