|
1 | 1 | 'use strict'
|
2 | 2 | var util = require('util')
|
3 | 3 | var Transport = require('winston-transport')
|
| 4 | +var winston = require('winston') |
| 5 | + |
4 | 6 | var common = require('winston/lib/winston/common')
|
5 | 7 | var _dirname = require('path').dirname
|
6 | 8 | var LogseneJS = require('logsene-js')
|
7 | 9 | var flat = require('flat')
|
8 | 10 |
|
9 | 11 | var Logsene = function (options) {
|
10 |
| - Transport.call(this, options) |
11 | 12 | options = options || {}
|
12 | 13 | if (!options.hasOwnProperty('flushOnExit')) {
|
13 | 14 | options.flushOnExit = true
|
14 | 15 | }
|
| 16 | + if (!options.levels) { |
| 17 | + options.levels = winston.config.npm.levels |
| 18 | + } |
| 19 | + Transport.call(this, options) |
15 | 20 | this.logCount = 0
|
16 | 21 | this.setSource = options.setLogSource
|
17 | 22 | if (options.hasOwnProperty('setSource')) {
|
@@ -47,24 +52,25 @@ var Logsene = function (options) {
|
47 | 52 | self.emit('flush', data)
|
48 | 53 | })
|
49 | 54 | var flushLogs = function (callback) {
|
| 55 | + var exitTimeout = 99000 |
50 | 56 | if (self.logCount < 1) {
|
51 | 57 | console.log(new Date().toISOString() + ' winston-logsene: flush: no logs in buffer')
|
52 |
| - callback(null, 200) |
| 58 | + callback(null, exitTimeout) |
53 | 59 | } else {
|
54 | 60 | console.log(new Date().toISOString() + ' winston-logsene: start flushing ' + self.logCount + ' logs before exit ...')
|
55 | 61 | self.logger.once('log', function (data) {
|
56 | 62 | console.log(new Date().toISOString() + ' winston-logsene: flush before exit: ' + data.count + ' logs send.')
|
57 |
| - callback(null, 200) |
| 63 | + callback(null, exitTimeout) |
58 | 64 | })
|
59 | 65 | self.logger.once('error', function (err) {
|
60 | 66 | console.log(new Date().toISOString() + ' winston-logsene: flush before exit error: ' + err)
|
61 |
| - callback(err, 200) |
| 67 | + callback(err, exitTimeout) |
62 | 68 | })
|
63 | 69 | process.nextTick(self.logger.send.bind(self.logger))
|
64 | 70 | // when no error or successful "log" event was received,
|
65 | 71 | // the process should terminate.
|
66 | 72 | // upstart waits max 10 seconds before kill -9
|
67 |
| - callback(null, 10000) |
| 73 | + callback(null, exitTimeout) |
68 | 74 | }
|
69 | 75 | }
|
70 | 76 | var logseneExitHandler = function (code) {
|
|
0 commit comments