Skip to content

Commit bac8b07

Browse files
es5->es6
1 parent 32dfa01 commit bac8b07

File tree

1 file changed

+28
-37
lines changed

1 file changed

+28
-37
lines changed

lib/winston-mongodb.js

Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -174,17 +174,17 @@ winston.transports.MongoDB = MongoDB;
174174
* Used by winston Logger.close on transports.
175175
*/
176176
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;
187179
}
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+
});
188188
};
189189

190190

@@ -193,60 +193,51 @@ MongoDB.prototype.close = function() {
193193
* @param {string} level Level at which to log the message.
194194
* @param {string} msg Message to log
195195
* @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.
197197
*/
198-
MongoDB.prototype.log = function(level, msg, opt_meta, callback) {
198+
MongoDB.prototype.log = function(level, msg, opt_meta, cb) {
199199
if (!this.logDb) {
200-
this._opQueue.push({
201-
method: 'log',
202-
args: arguments
203-
});
200+
this._opQueue.push({method: 'log', args: arguments});
204201
return;
205202
}
206-
207-
var self = this;
208-
209203
/**
210204
* Avoid reentrancy that can be not assumed by database code.
211205
* If database logs, better not to call database itself in the same call.
212206
*/
213-
process.nextTick(function() {
214-
if (self.silent) {
215-
callback(null, true);
207+
process.nextTick(()=>{
208+
if (this.silent) {
209+
cb(null, true);
216210
return;
217211
}
218-
219212
function onError(err) {
220-
self.emit('error', err);
221-
callback(err, null);
213+
this.emit('error', err);
214+
cb(err, null);
222215
}
223-
224-
self.logDb.collection(self.collection, function(err, col) {
216+
this.logDb.collection(this.collection, (err, col)=>{
225217
if (err) {
226218
onError(err);
227219
return;
228220
}
229221

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;
232224
entry.timestamp = new Date();
233225
entry.level = level;
234226
entry.meta = helpers.prepareMetaData(opt_meta);
235-
if (self.storeHost) {
236-
entry.hostname = self.hostname;
227+
if (this.storeHost) {
228+
entry.hostname = this.hostname;
237229
}
238-
if (self.label) {
239-
entry.label = self.label;
230+
if (this.label) {
231+
entry.label = this.label;
240232
}
241233

242-
col.insertOne(entry, function(err) {
234+
col.insertOne(entry, err=>{
243235
if (err) {
244236
onError(err);
245237
return;
246238
}
247-
248-
self.emit('logged');
249-
callback(null, true);
239+
this.emit('logged');
240+
cb(null, true);
250241
});
251242
});
252243
});

0 commit comments

Comments
 (0)