From 86279495bb7ee6c7ba0eb7224ad8cefc36d54279 Mon Sep 17 00:00:00 2001 From: Pratik Fandade Date: Sun, 6 Oct 2024 19:00:10 -0400 Subject: [PATCH 1/4] Addition of Container.getAll() method as discussed in #970 --- lib/winston/container.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/winston/container.js b/lib/winston/container.js index 57720306a..5080b7157 100644 --- a/lib/winston/container.js +++ b/lib/winston/container.js @@ -65,6 +65,19 @@ module.exports = class Container { return this.add(id, options); } + /** + * Retreives all `winston.Logger` instances for the specified `regex`. + * @param {!string} id - The regrex to match the Loggers to get. + * @returns {Map} - A Map of Logger instances matching the regex. + */ + getAll(regex) { + if(regex) { + return new Map([...this.loggers].filter(([key]) => key.match(regex))); + } + + return this.loggers; + } + /** * Check if the container has a logger with the id. * @param {?string} id - The id of the Logger instance to find. From 67e07299e5905051e7f95fbeae260383af41abf5 Mon Sep 17 00:00:00 2001 From: David Hyde Date: Sun, 13 Oct 2024 21:09:55 -0500 Subject: [PATCH 2/4] Update lib/winston/container.js --- lib/winston/container.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/winston/container.js b/lib/winston/container.js index 5080b7157..e97bd6973 100644 --- a/lib/winston/container.js +++ b/lib/winston/container.js @@ -71,7 +71,7 @@ module.exports = class Container { * @returns {Map} - A Map of Logger instances matching the regex. */ getAll(regex) { - if(regex) { + if (regex) { return new Map([...this.loggers].filter(([key]) => key.match(regex))); } From 8dfa4e23b099bf61f04f401478c9c667951810db Mon Sep 17 00:00:00 2001 From: David Hyde Date: Sun, 13 Oct 2024 21:10:00 -0500 Subject: [PATCH 3/4] Update lib/winston/container.js --- lib/winston/container.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/winston/container.js b/lib/winston/container.js index e97bd6973..4a53f68fd 100644 --- a/lib/winston/container.js +++ b/lib/winston/container.js @@ -67,7 +67,7 @@ module.exports = class Container { /** * Retreives all `winston.Logger` instances for the specified `regex`. - * @param {!string} id - The regrex to match the Loggers to get. + * @param {!string} regex - The regex for filtering the Loggers to get. * @returns {Map} - A Map of Logger instances matching the regex. */ getAll(regex) { From 160bea75478c8a59f79dd879d7d97b34e6ac9926 Mon Sep 17 00:00:00 2001 From: Pratik Fandade Date: Wed, 23 Oct 2024 17:42:41 -0400 Subject: [PATCH 4/4] add unit test for coverage --- test/unit/winston/container.test.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/unit/winston/container.test.js b/test/unit/winston/container.test.js index 3008ee08b..bbb0aa17c 100644 --- a/test/unit/winston/container.test.js +++ b/test/unit/winston/container.test.js @@ -23,6 +23,29 @@ describe('Container', function () { assume(container.get('default-test')).equals(defaultTest); }); + it('.getAll(default-test)', function () { + container.add('appLogger'); + container.add('serviceLogger'); + + var allLogger = container.getAll(); + var appLogger = container.getAll(/^app/); + var matchLogg = container.getAll(/Logger$/); + var emptyLogg = container.getAll(/Library/); + + assume(allLogger.size).equals(3); + assume(allLogger.has('appLogger')).true(); + assume(allLogger.has('serviceLogger')).true(); + + assume(appLogger.size).equals(1); + assume(appLogger.has('appLogger')).true(); + + assume(matchLogg.size).equals(2); + assume(matchLogg.has('appLogger')).true(); + assume(matchLogg.has('serviceLogger')).true(); + + assume(emptyLogg.size).equals(0); + }); + it('.has(default-test)', function () { assume(container.has('default-test')).true(); });