1
0
mirror of https://github.com/videojs/video.js.git synced 2024-12-04 10:34:51 +02:00

feat: cap log history at 1000 items (#6192)

This commit is contained in:
Brandon Casey 2019-08-29 17:32:34 -04:00 committed by Gary Katsevman
parent 99b610bd92
commit 5fa4257b91
2 changed files with 20 additions and 0 deletions

View File

@ -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

View File

@ -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');
});