Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix calling log callbacks

  • Loading branch information...
commit db47e60fc239d3fa7f380f355c0806eda04e51bc 1 parent cd53888
@yosefd yosefd authored
Showing with 14 additions and 12 deletions.
  1. +14 −12 lib/winston-mongodb.js
View
26 lib/winston-mongodb.js
@@ -9,7 +9,7 @@
var util = require('util'),
mongodb = require('mongodb'),
winston = require('winston');
-
+
//
// ### function MongoDB (options)
// Constructor for the MongoDB transport object.
@@ -35,7 +35,7 @@ var MongoDB = exports.MongoDB = function (options) {
this.state = 'unopened';
this.pending = [];
- this.client = new mongodb.Db(this.db, new mongodb.Server(this.host, this.port, {}), {
+ this.client = new mongodb.Db(this.db, new mongodb.Server(this.host, this.port, {}), {
native_parser : false
});
};
@@ -46,7 +46,7 @@ var MongoDB = exports.MongoDB = function (options) {
util.inherits(MongoDB, winston.Transport);
//
-// Define a getter so that `winston.transports.MongoDB`
+// Define a getter so that `winston.transports.MongoDB`
// is available and thus backwards compatible.
//
winston.transports.MongoDB = MongoDB;
@@ -61,19 +61,21 @@ winston.transports.MongoDB = MongoDB;
//
MongoDB.prototype.log = function (level, msg, meta, callback) {
var self = this;
-
+
if (this.silent) {
return callback(null, true);
}
-
+
this.open(function (err) {
if (err) {
- return self.emit('error', err);
+ self.emit('error', err);
+ return callback(err, null);
}
-
+
self._db.collection(self.collection, function (err, col) {
if (err) {
- return self.emit('error', err);
+ self.emit('error', err);
+ return callback(err, null);
}
var entry = {
@@ -85,15 +87,15 @@ MongoDB.prototype.log = function (level, msg, meta, callback) {
col.save(entry, { safe: self.safe }, function (err, doc) {
if (err) {
- return self.emit('error', err);
+ self.emit('error', err);
+ return callback(err, null);
}
self.emit('logged');
+ return callback(null, true);
});
});
});
-
- callback(null, true);
};
//
@@ -108,7 +110,7 @@ MongoDB.prototype.open = function (callback) {
if (this.state === 'opening' || this.state === 'unopened') {
//
// While opening our MongoDB connection, append any callback
- // to a list that is managed by this instance.
+ // to a list that is managed by this instance.
//
this.pending.push(callback);
Please sign in to comment.
Something went wrong with that request. Please try again.