diff --git a/src/js/utils/create-logger.js b/src/js/utils/create-logger.js index a37bf693f7..33f89d8f92 100644 --- a/src/js/utils/create-logger.js +++ b/src/js/utils/create-logger.js @@ -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 diff --git a/test/unit/utils/log.test.js b/test/unit/utils/log.test.js index bff8952942..9c60f3635d 100644 --- a/test/unit/utils/log.test.js +++ b/test/unit/utils/log.test.js @@ -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'); +});