From 1809d6e403a0b223dd211bc525ff2c7efea3ecc1 Mon Sep 17 00:00:00 2001 From: Ersun Warncke Date: Tue, 12 Mar 2019 08:23:37 -0400 Subject: [PATCH] filter out error logs in buffer --- libraries/logger/logging-manager.js | 6 ++++-- .../logger/test/unit/loggingManagerTests.js | 17 +++++++++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/libraries/logger/logging-manager.js b/libraries/logger/logging-manager.js index 92a8f88171..cf702ac821 100644 --- a/libraries/logger/logging-manager.js +++ b/libraries/logger/logging-manager.js @@ -171,8 +171,10 @@ const Logger = module.exports = { }, error(attributes, message, ...args) { - if (this.ringBuffer !== null) { - attributes.logBuffer = this.ringBuffer.records + if (this.ringBuffer !== null && Array.isArray(this.ringBuffer.records)) { + attributes.logBuffer = this.ringBuffer.records.filter(function (record) { + return record.level !== 50 + }) } this.logger.error(attributes, message, ...Array.from(args)) if (this.raven != null) { diff --git a/libraries/logger/test/unit/loggingManagerTests.js b/libraries/logger/test/unit/loggingManagerTests.js index c45ef4e564..dc8ac244b2 100644 --- a/libraries/logger/test/unit/loggingManagerTests.js +++ b/libraries/logger/test/unit/loggingManagerTests.js @@ -334,6 +334,10 @@ describe('LoggingManager', function() { }, { msg: 'log 2' + }, + { + level: 50, + msg: 'error' } ] }) @@ -350,10 +354,15 @@ describe('LoggingManager', function() { process.env['LOG_RING_BUFFER_SIZE'] = undefined }) - it('should include buffered logs in error log', function() { - this.mockBunyanLogger.error.lastCall.args[0].logBuffer.should.equal( - this.logBufferMock - ) + it('should include buffered logs in error log and filter out error logs in buffer', function() { + this.mockBunyanLogger.error.lastCall.args[0].logBuffer.should.deep.equal([ + { + msg: 'log 1' + }, + { + msg: 'log 2' + }, + ]) }) })