From ade6dd8ea03a5948ebd23d0362dc21ea5e156099 Mon Sep 17 00:00:00 2001 From: Jakub Chmura Date: Mon, 25 Aug 2014 20:56:37 +0200 Subject: [PATCH] Adjusting and adding new tests for logLevelFilter to handle the maxLevel option. --- test/logLevelFilter-test.js | 25 +++++++++++++++++++------ test/with-logLevelFilter.json | 15 ++++++++++++++- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/test/logLevelFilter-test.js b/test/logLevelFilter-test.js index 2280a96..b3deb05 100644 --- a/test/logLevelFilter-test.js +++ b/test/logLevelFilter-test.js @@ -22,6 +22,7 @@ vows.describe('log4js logLevelFilter').addBatch({ require('../lib/appenders/logLevelFilter') .appender( 'ERROR', + undefined, function(evt) { logEvents.push(evt); } ), "logLevelTest" @@ -48,13 +49,16 @@ vows.describe('log4js logLevelFilter').addBatch({ remove(__dirname + '/logLevelFilter.log'); remove(__dirname + '/logLevelFilter-warnings.log'); + remove(__dirname + '/logLevelFilter-debugs.log'); log4js.configure('test/with-logLevelFilter.json'); logger = log4js.getLogger("tests"); - logger.info('main'); - logger.error('both'); - logger.warn('both'); - logger.debug('main'); + logger.debug('debug'); + logger.info('info'); + logger.error('error'); + logger.warn('warn'); + logger.debug('debug'); + logger.trace('trace'); //wait for the file system to catch up setTimeout(this.callback, 500); }, @@ -64,7 +68,7 @@ vows.describe('log4js logLevelFilter').addBatch({ }, 'should contain all log messages': function (contents) { var messages = contents.trim().split(EOL); - assert.deepEqual(messages, ['main','both','both','main']); + assert.deepEqual(messages, ['debug','info','error','warn','debug','trace']); } }, 'tmp-tests-warnings.log': { @@ -73,7 +77,16 @@ vows.describe('log4js logLevelFilter').addBatch({ }, 'should contain only error and warning log messages': function(contents) { var messages = contents.trim().split(EOL); - assert.deepEqual(messages, ['both','both']); + assert.deepEqual(messages, ['error','warn']); + } + }, + 'tmp-tests-debugs.log': { + topic: function() { + fs.readFile(__dirname + '/logLevelFilter-debugs.log','utf8',this.callback); + }, + 'should contain only trace and debug log messages': function(contents) { + var messages = contents.trim().split(EOL); + assert.deepEqual(messages, ['debug','debug','trace']); } } } diff --git a/test/with-logLevelFilter.json b/test/with-logLevelFilter.json index d564ace..7bcd8ad 100644 --- a/test/with-logLevelFilter.json +++ b/test/with-logLevelFilter.json @@ -12,6 +12,19 @@ } } }, + { + "category": "tests", + "type": "logLevelFilter", + "level": "TRACE", + "maxLevel": "DEBUG", + "appender": { + "type": "file", + "filename": "test/logLevelFilter-debugs.log", + "layout": { + "type": "messagePassThrough" + } + } + }, { "category": "tests", "type": "file", @@ -23,6 +36,6 @@ ], "levels": { - "tests": "DEBUG" + "tests": "TRACE" } }