Skip to content

Commit

Permalink
fix terminate after log flush
Browse files Browse the repository at this point in the history
  • Loading branch information
megastef committed Jul 29, 2016
1 parent 62aa16b commit e4be2e8
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 || {}
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit e4be2e8

Please sign in to comment.