@@ -174,17 +174,17 @@ winston.transports.MongoDB = MongoDB;
174
174
* Used by winston Logger.close on transports.
175
175
*/
176
176
MongoDB . prototype . close = function ( ) {
177
- var self = this ;
178
- if ( this . logDb ) {
179
- this . logDb . close ( function ( err ) {
180
- if ( err ) {
181
- console . error ( 'Winston MongoDB transport encountered on error during' +
182
- ' closing.' , err ) ;
183
- } else {
184
- self . logDb = null ;
185
- }
186
- } ) ;
177
+ if ( ! this . logDb ) {
178
+ return ;
187
179
}
180
+ this . logDb . close ( err => {
181
+ if ( err ) {
182
+ console . error ( 'Winston MongoDB transport encountered on error during' +
183
+ ' closing.' , err ) ;
184
+ } else {
185
+ this . logDb = null ;
186
+ }
187
+ } ) ;
188
188
} ;
189
189
190
190
@@ -193,60 +193,51 @@ MongoDB.prototype.close = function() {
193
193
* @param {string } level Level at which to log the message.
194
194
* @param {string } msg Message to log
195
195
* @param {Object= } opt_meta Additional metadata to attach
196
- * @param {Function } callback Continuation to respond to when complete.
196
+ * @param {Function } cb Continuation to respond to when complete.
197
197
*/
198
- MongoDB . prototype . log = function ( level , msg , opt_meta , callback ) {
198
+ MongoDB . prototype . log = function ( level , msg , opt_meta , cb ) {
199
199
if ( ! this . logDb ) {
200
- this . _opQueue . push ( {
201
- method : 'log' ,
202
- args : arguments
203
- } ) ;
200
+ this . _opQueue . push ( { method : 'log' , args : arguments } ) ;
204
201
return ;
205
202
}
206
-
207
- var self = this ;
208
-
209
203
/**
210
204
* Avoid reentrancy that can be not assumed by database code.
211
205
* If database logs, better not to call database itself in the same call.
212
206
*/
213
- process . nextTick ( function ( ) {
214
- if ( self . silent ) {
215
- callback ( null , true ) ;
207
+ process . nextTick ( ( ) => {
208
+ if ( this . silent ) {
209
+ cb ( null , true ) ;
216
210
return ;
217
211
}
218
-
219
212
function onError ( err ) {
220
- self . emit ( 'error' , err ) ;
221
- callback ( err , null ) ;
213
+ this . emit ( 'error' , err ) ;
214
+ cb ( err , null ) ;
222
215
}
223
-
224
- self . logDb . collection ( self . collection , function ( err , col ) {
216
+ this . logDb . collection ( this . collection , ( err , col ) => {
225
217
if ( err ) {
226
218
onError ( err ) ;
227
219
return ;
228
220
}
229
221
230
- var entry = { } ;
231
- entry . message = self . decolorize ? msg . replace ( / \u001b \[ [ 0 - 9 ] { 1 , 2 } m / g, '' ) : msg ;
222
+ let entry = { } ;
223
+ entry . message = this . decolorize ? msg . replace ( / \u001b \[ [ 0 - 9 ] { 1 , 2 } m / g, '' ) : msg ;
232
224
entry . timestamp = new Date ( ) ;
233
225
entry . level = level ;
234
226
entry . meta = helpers . prepareMetaData ( opt_meta ) ;
235
- if ( self . storeHost ) {
236
- entry . hostname = self . hostname ;
227
+ if ( this . storeHost ) {
228
+ entry . hostname = this . hostname ;
237
229
}
238
- if ( self . label ) {
239
- entry . label = self . label ;
230
+ if ( this . label ) {
231
+ entry . label = this . label ;
240
232
}
241
233
242
- col . insertOne ( entry , function ( err ) {
234
+ col . insertOne ( entry , err => {
243
235
if ( err ) {
244
236
onError ( err ) ;
245
237
return ;
246
238
}
247
-
248
- self . emit ( 'logged' ) ;
249
- callback ( null , true ) ;
239
+ this . emit ( 'logged' ) ;
240
+ cb ( null , true ) ;
250
241
} ) ;
251
242
} ) ;
252
243
} ) ;
0 commit comments