@@ -3,7 +3,8 @@ var util = require('util')
3
3
var Transport = require ( 'winston-transport' )
4
4
var winston = require ( 'winston' )
5
5
6
- var common = require ( 'winston/lib/winston/common' )
6
+ // var common = require('winston/lib/winston/common')
7
+ const winstonCompat = require ( 'winston-compat' )
7
8
var _dirname = require ( 'path' ) . dirname
8
9
var LogseneJS = require ( 'logsene-js' )
9
10
var flat = require ( 'flat' )
@@ -25,7 +26,7 @@ var Logsene = function (options) {
25
26
this . setSource = false
26
27
}
27
28
this . logsene_debug = options . logsene_debug
28
- this . flatOptions = options . flatOptions || { safe : true , delimiter : '_' }
29
+ this . flatOptions = options . flatOptions || { safe : true , delimiter : '_' }
29
30
this . json = options . json || false
30
31
this . colorize = options . colorize || false
31
32
this . prettyPrint = options . prettyPrint || false
@@ -92,6 +93,21 @@ var Logsene = function (options) {
92
93
} )
93
94
}
94
95
96
+ // maybe this?
97
+ if ( options . handleErrors ) {
98
+ process . on ( 'error' , function ( err ) {
99
+ console . log ( new Date ( ) . toISOString ( ) + ' winston-logsene: unhandledError: ' + err + ' ' + err . stack )
100
+ self . logger . log ( 'error' , err . stack || err . toString ( ) , err )
101
+ flushLogs ( function ( flushErr , exitTime ) {
102
+ if ( options . exitOnError ) {
103
+ setTimeout ( function ( ) {
104
+ process . exit ( - 1 )
105
+ } , exitTime )
106
+ }
107
+ } )
108
+ } )
109
+ }
110
+
95
111
process . on ( 'unhandledRejection' , function ( err ) {
96
112
console . log ( new Date ( ) . toISOString ( ) + ' winston-logsene: unhandledRejection: ' + err + ' ' + err . stack )
97
113
self . logger . log ( 'warning' , err . stack || err . toString ( ) , err )
@@ -147,7 +163,7 @@ Logsene.prototype.log = function (meta, callback) {
147
163
return callback ( null , true )
148
164
}
149
165
if ( this . setSource ) {
150
- if ( meta && ( ! meta [ ' source' ] ) ) {
166
+ if ( meta && ( ! meta . source ) ) {
151
167
meta . source = this . source
152
168
}
153
169
}
@@ -159,10 +175,10 @@ Logsene.prototype.log = function (meta, callback) {
159
175
if ( ! msg ) {
160
176
msg = meta . stack || meta . message
161
177
}
162
- metaData = { error_stack : meta . stack || meta . message }
178
+ metaData = { error_stack : meta . stack || meta . message }
163
179
}
164
180
if ( this . logsene_debug ) {
165
- var output = common . log ( {
181
+ var output = winstonCompat . log ( {
166
182
colorize : this . colorize ,
167
183
json : this . json ,
168
184
level : level ,
0 commit comments