Skip to content
This repository was archived by the owner on Apr 21, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions lib/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,19 +384,35 @@ const flushAll = function(cb) {
if (!cb || typeof cb !== 'function') {
cb = debug;
}

// Variables used to wait for all the flushes to be completed
let counter = 0;
const loggersCount = loggers.length;
const complete = (errors) => {
if (errors.length > 0) {
return cb(`The following errors happened while flushing all loggers: ${errors}`);
}
return cb();

};

const errors = [];
loggers.forEach((logger) => {
logger._flush((err) => {
if (err) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use error for readability since the array is errors - basically, adding error into errors: the list of errors

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it makes a difference.

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;
Expand Down
3 changes: 0 additions & 3 deletions test/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down