Skip to content

Commit

Permalink
add default log levels, adjust exitTimeout
Browse files Browse the repository at this point in the history
  • Loading branch information
megastef committed Jul 25, 2019
1 parent ab8e2a5 commit 6851fc5
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
'use strict'
var util = require('util')
var Transport = require('winston-transport')
var winston = require('winston')

var common = require('winston/lib/winston/common')
var _dirname = require('path').dirname
var LogseneJS = require('logsene-js')
var flat = require('flat')

var Logsene = function (options) {
Transport.call(this, options)
options = options || {}
if (!options.hasOwnProperty('flushOnExit')) {
options.flushOnExit = true
}
if (!options.levels) {
options.levels = winston.config.npm.levels
}
Transport.call(this, options)
this.logCount = 0
this.setSource = options.setLogSource
if (options.hasOwnProperty('setSource')) {
Expand Down Expand Up @@ -47,24 +52,25 @@ var Logsene = function (options) {
self.emit('flush', data)
})
var flushLogs = function (callback) {
var exitTimeout = 99000
if (self.logCount < 1) {
console.log(new Date().toISOString() + ' winston-logsene: flush: no logs in buffer')
callback(null, 200)
callback(null, exitTimeout)
} else {
console.log(new Date().toISOString() + ' winston-logsene: start flushing ' + self.logCount + ' logs before exit ...')
self.logger.once('log', function (data) {
console.log(new Date().toISOString() + ' winston-logsene: flush before exit: ' + data.count + ' logs send.')
callback(null, 200)
callback(null, exitTimeout)
})
self.logger.once('error', function (err) {
console.log(new Date().toISOString() + ' winston-logsene: flush before exit error: ' + err)
callback(err, 200)
callback(err, exitTimeout)
})
process.nextTick(self.logger.send.bind(self.logger))
// when no error or successful "log" event was received,
// the process should terminate.
// upstart waits max 10 seconds before kill -9
callback(null, 10000)
callback(null, exitTimeout)
}
}
var logseneExitHandler = function (code) {
Expand Down

0 comments on commit 6851fc5

Please sign in to comment.