Skip to content

Commit 6851fc5

Browse files
committed
add default log levels, adjust exitTimeout
1 parent ab8e2a5 commit 6851fc5

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

lib/index.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
'use strict'
22
var util = require('util')
33
var Transport = require('winston-transport')
4+
var winston = require('winston')
5+
46
var common = require('winston/lib/winston/common')
57
var _dirname = require('path').dirname
68
var LogseneJS = require('logsene-js')
79
var flat = require('flat')
810

911
var Logsene = function (options) {
10-
Transport.call(this, options)
1112
options = options || {}
1213
if (!options.hasOwnProperty('flushOnExit')) {
1314
options.flushOnExit = true
1415
}
16+
if (!options.levels) {
17+
options.levels = winston.config.npm.levels
18+
}
19+
Transport.call(this, options)
1520
this.logCount = 0
1621
this.setSource = options.setLogSource
1722
if (options.hasOwnProperty('setSource')) {
@@ -47,24 +52,25 @@ var Logsene = function (options) {
4752
self.emit('flush', data)
4853
})
4954
var flushLogs = function (callback) {
55+
var exitTimeout = 99000
5056
if (self.logCount < 1) {
5157
console.log(new Date().toISOString() + ' winston-logsene: flush: no logs in buffer')
52-
callback(null, 200)
58+
callback(null, exitTimeout)
5359
} else {
5460
console.log(new Date().toISOString() + ' winston-logsene: start flushing ' + self.logCount + ' logs before exit ...')
5561
self.logger.once('log', function (data) {
5662
console.log(new Date().toISOString() + ' winston-logsene: flush before exit: ' + data.count + ' logs send.')
57-
callback(null, 200)
63+
callback(null, exitTimeout)
5864
})
5965
self.logger.once('error', function (err) {
6066
console.log(new Date().toISOString() + ' winston-logsene: flush before exit error: ' + err)
61-
callback(err, 200)
67+
callback(err, exitTimeout)
6268
})
6369
process.nextTick(self.logger.send.bind(self.logger))
6470
// when no error or successful "log" event was received,
6571
// the process should terminate.
6672
// upstart waits max 10 seconds before kill -9
67-
callback(null, 10000)
73+
callback(null, exitTimeout)
6874
}
6975
}
7076
var logseneExitHandler = function (code) {

0 commit comments

Comments
 (0)