From acf2b9880f9724356b928051a06ff50eaf1bfdb6 Mon Sep 17 00:00:00 2001 From: Guido Lodetti Date: Thu, 17 Oct 2019 15:42:43 +0200 Subject: [PATCH 1/5] Update logger.js `flushAll` callback was called too early --- lib/logger.js | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/lib/logger.js b/lib/logger.js index 7574090..db6a7ef 100644 --- a/lib/logger.js +++ b/lib/logger.js @@ -384,19 +384,32 @@ const flushAll = function(cb) { if (!cb || typeof cb !== 'function') { cb = debug; } + + // Variables used to wait for all the flushes to be completed + const counter = 0; + const loggersCount = loggers.length; + const complete = (errors) => { + if (errors.length > 0) { + return cb(`The following errors happened while flushing all loggers: ${errors}`); + } else { + return cb(); + } + } + const errors = []; loggers.forEach((logger) => { logger._flush((err) => { if (err) { errors.push(err); } + // Counter is incremented after each flush + if (++counter === loggersCount) { + // Flushed all the loggers + // Completes by calling the callback + complete(errors); + } }); }); - - if (errors.length > 0) { - return cb(`The following errors happened while flushing all loggers: ${errors}`); - } - return cb(); }; exports.Logger = Logger; From 6618c7206ebd60c3a479a669cb3e6e7009193116 Mon Sep 17 00:00:00 2001 From: Guido Lodetti Date: Thu, 17 Oct 2019 16:09:08 +0200 Subject: [PATCH 2/5] Update logger.js Fix typo --- lib/logger.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/logger.js b/lib/logger.js index db6a7ef..3044d60 100644 --- a/lib/logger.js +++ b/lib/logger.js @@ -386,7 +386,7 @@ const flushAll = function(cb) { } // Variables used to wait for all the flushes to be completed - const counter = 0; + let counter = 0; const loggersCount = loggers.length; const complete = (errors) => { if (errors.length > 0) { From 1f0e49c342a60a615076ae99a3e036230531b7f4 Mon Sep 17 00:00:00 2001 From: vilyapilya <13.veter@gmail.com> Date: Thu, 7 Nov 2019 17:23:45 -0800 Subject: [PATCH 3/5] lints --- lib/logger.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/logger.js b/lib/logger.js index 3044d60..7a77583 100644 --- a/lib/logger.js +++ b/lib/logger.js @@ -387,15 +387,15 @@ const flushAll = function(cb) { // Variables used to wait for all the flushes to be completed let counter = 0; - const loggersCount = loggers.length; + const loggersCount = loggers.length; const complete = (errors) => { if (errors.length > 0) { return cb(`The following errors happened while flushing all loggers: ${errors}`); - } else { - return cb(); } - } - + return cb(); + + }; + const errors = []; loggers.forEach((logger) => { logger._flush((err) => { @@ -404,8 +404,11 @@ const flushAll = function(cb) { } // Counter is incremented after each flush if (++counter === loggersCount) { - // Flushed all the loggers - // Completes by calling the callback + + /* + * Flushed all the loggers + * Completes by calling the callback + */ complete(errors); } }); From 6a5162d62b3c9d8eb5397e5e4ee284abf5857ea4 Mon Sep 17 00:00:00 2001 From: vilyapilya <13.veter@gmail.com> Date: Fri, 8 Nov 2019 11:13:35 -0800 Subject: [PATCH 4/5] rebase --- test/logger.js | 7 ------- 1 file changed, 7 deletions(-) diff --git a/test/logger.js b/test/logger.js index 1936866..b625fc6 100644 --- a/test/logger.js +++ b/test/logger.js @@ -288,9 +288,6 @@ describe('Index meta', function() { }); describe('Input validation', function() { - afterEach(function(done) { - Logger.flushAll(done); - }); it('Sanity checks for Ingestion Key', function(done) { const bogusKeys = [ 'THIS KEY IS TOO LONG THIS KEY IS TOO LONG THIS KEY IS TOO LONG THIS KEY IS TOO LONG THIS KEY IS TOO LONG THIS KEY IS TOO LONG' @@ -436,10 +433,6 @@ describe('ambient meta', function() { const options = testHelper.createOptions(); const ambientLogger = Logger.createLogger(testHelper.apikey, options); - beforeEach(function() { - Logger.flushAll(); - }); - it('add string ambient meta to a string log line', function() { ambientLogger.addMetaProperty('ambient', 'someAmbientMeta'); ambientLogger.log('Sent a string log'); From b1fe4be56fea720e4c179719a7c211f255948960 Mon Sep 17 00:00:00 2001 From: vilyapilya <13.veter@gmail.com> Date: Fri, 8 Nov 2019 11:23:16 -0800 Subject: [PATCH 5/5] rebase and fil --- test/logger.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/logger.js b/test/logger.js index b625fc6..479b958 100644 --- a/test/logger.js +++ b/test/logger.js @@ -433,6 +433,10 @@ describe('ambient meta', function() { const options = testHelper.createOptions(); const ambientLogger = Logger.createLogger(testHelper.apikey, options); + beforeEach(function() { + Logger.flushAll(); + }); + it('add string ambient meta to a string log line', function() { ambientLogger.addMetaProperty('ambient', 'someAmbientMeta'); ambientLogger.log('Sent a string log');