Skip to content

Commit

Permalink
feat: cap log history at 1000 items (#6192)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonocasey authored and gkatsev committed Aug 29, 2019
1 parent 99b610b commit 5fa4257
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/js/utils/create-logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ const LogByTypeFactory = (name, log) => (type, level, args) => {
// Add a clone of the args at this point to history.
if (history) {
history.push([].concat(args));

// only store 1000 history entries
const splice = history.length - 1000;

history.splice(0, splice > 0 ? splice : 0);
}

// If there's no console then don't try to output messages, but they will
Expand Down
15 changes: 15 additions & 0 deletions test/unit/utils/log.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,18 @@ QUnit.test('falls back to info and log when debug is not supported', function(as
assert.notOk(window.console.warn.called, 'warn was not called');
assert.notOk(window.console.error.called, 'error was not called');
});

QUnit.test('history only retains 1000 items', function(assert) {
// Need to reset history here because there are extra messages logged
// when running via Karma.
log.history.clear();

for (let i = 1; i <= 1005; i++) {
log(i);
}

const hist = log.history();

assert.equal(hist.length, 1000, 'only 1000 items in history');
assert.deepEqual([hist[0], hist[hist.length - 1 ]], [['VIDEOJS:', 6], ['VIDEOJS:', 1005]], 'keeps most recent items');
});

0 comments on commit 5fa4257

Please sign in to comment.