Skip to content

Commit

Permalink
version 1.5.0: Logger.close support
Browse files Browse the repository at this point in the history
  • Loading branch information
yurijmikhalevich committed May 24, 2016
1 parent 09ba086 commit 47abd92
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 7 additions & 5 deletions lib/winston-mongodb.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,24 +194,26 @@ util.inherits(MongoDB, winston.Transport);
*/
winston.transports.MongoDB = MongoDB;


/**
* Closes MongoDB connection so using process would not hang up.
* Used by winston Logger.close on transports.
*/
MongoDB.prototype.close = function () {
MongoDB.prototype.close = function() {
var self = this;

if (this.logDb) {
this.logDb.close(function (error) {
if(error) {
console.error('Winston MongoDB transport encountered on error during closing.', error);
this.logDb.close(function(err) {
if (err) {
console.error('Winston MongoDB transport encountered on error during' +
' closing.', err);
} else {
self.logDb = null;
}
});
}
};


/**
* Core logging method exposed to Winston. Metadata is optional.
* @param {string} level Level at which to log the message.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "winston-mongodb",
"license": "MIT",
"version": "1.4.0",
"version": "1.5.0",
"description": "A MongoDB transport for winston",
"author": "Charlie Robbins <[email protected]>",
"contributors": [
Expand Down

0 comments on commit 47abd92

Please sign in to comment.