Adjusting and adding new tests for logLevelFilter to handle the maxLevel option.

This commit is contained in:
Jakub Chmura 2014-08-25 20:56:37 +02:00
parent 00c62c7fa6
commit ade6dd8ea0
2 changed files with 33 additions and 7 deletions

View File

@ -22,6 +22,7 @@ vows.describe('log4js logLevelFilter').addBatch({
require('../lib/appenders/logLevelFilter') require('../lib/appenders/logLevelFilter')
.appender( .appender(
'ERROR', 'ERROR',
undefined,
function(evt) { logEvents.push(evt); } function(evt) { logEvents.push(evt); }
), ),
"logLevelTest" "logLevelTest"
@ -48,13 +49,16 @@ vows.describe('log4js logLevelFilter').addBatch({
remove(__dirname + '/logLevelFilter.log'); remove(__dirname + '/logLevelFilter.log');
remove(__dirname + '/logLevelFilter-warnings.log'); remove(__dirname + '/logLevelFilter-warnings.log');
remove(__dirname + '/logLevelFilter-debugs.log');
log4js.configure('test/with-logLevelFilter.json'); log4js.configure('test/with-logLevelFilter.json');
logger = log4js.getLogger("tests"); logger = log4js.getLogger("tests");
logger.info('main'); logger.debug('debug');
logger.error('both'); logger.info('info');
logger.warn('both'); logger.error('error');
logger.debug('main'); logger.warn('warn');
logger.debug('debug');
logger.trace('trace');
//wait for the file system to catch up //wait for the file system to catch up
setTimeout(this.callback, 500); setTimeout(this.callback, 500);
}, },
@ -64,7 +68,7 @@ vows.describe('log4js logLevelFilter').addBatch({
}, },
'should contain all log messages': function (contents) { 'should contain all log messages': function (contents) {
var messages = contents.trim().split(EOL); 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': { 'tmp-tests-warnings.log': {
@ -73,7 +77,16 @@ vows.describe('log4js logLevelFilter').addBatch({
}, },
'should contain only error and warning log messages': function(contents) { 'should contain only error and warning log messages': function(contents) {
var messages = contents.trim().split(EOL); 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']);
} }
} }
} }

View File

@ -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", "category": "tests",
"type": "file", "type": "file",
@ -23,6 +36,6 @@
], ],
"levels": { "levels": {
"tests": "DEBUG" "tests": "TRACE"
} }
} }