diff --git a/lib/winston/container.js b/lib/winston/container.js index cb4812a40..e9b5db1b6 100644 --- a/lib/winston/container.js +++ b/lib/winston/container.js @@ -58,6 +58,16 @@ Container.prototype.get = Container.prototype.add = function (id, options) { return this.loggers[id]; }; +// +// ### function close (id) +// #### @id {string} **Optional** Id of the Logger instance to find +// Returns a boolean value indicating if this instance +// has a logger with the specified `id`. +// +Container.prototype.has = function (id) { + return !!this.loggers[id]; +}; + // // ### function close (id) // #### @id {string} **Optional** Id of the Logger instance to close diff --git a/test/container-test.js b/test/container-test.js index bcbba5ed1..ec6ec3424 100644 --- a/test/container-test.js +++ b/test/container-test.js @@ -32,6 +32,17 @@ vows.describe('winston/container').addBatch({ assert.isTrue(existing === logger); } }, + "the has() method": { + topic: function (logger, container) { + this.callback.apply(this, arguments); + }, + "should indicate `default-test` logger exists": function (existing, container) { + assert.isTrue(container.has('default-test')); + }, + "should indicate `not-has` logger doesnt exists": function (existing, container) { + assert.isFalse(container.has('not-has')); + } + }, "the close() method": { topic: function (logger, container) { this.callback.apply(this, arguments);