more linting

This commit is contained in:
Gareth Jones
2013-05-27 07:44:59 +10:00
parent 7cb7e6df72
commit 1ad4977aec

View File

@@ -1,69 +1,78 @@
"use strict";
var vows = require('vows') var vows = require('vows')
, fs = require('fs') , fs = require('fs')
, assert = require('assert'); , assert = require('assert');
function remove(filename) { function remove(filename) {
try { try {
fs.unlinkSync(filename); fs.unlinkSync(filename);
} catch (e) { } catch (e) {
//doesn't really matter if it failed //doesn't really matter if it failed
} }
} }
vows.describe('log4js logLevelFilter').addBatch({ vows.describe('log4js logLevelFilter').addBatch({
'appender': { 'appender': {
topic: function() { topic: function() {
var log4js = require('../lib/log4js'), logEvents = [], logger; var log4js = require('../lib/log4js'), logEvents = [], logger;
log4js.clearAppenders(); log4js.clearAppenders();
log4js.addAppender(require('../lib/appenders/logLevelFilter').appender('ERROR', function(evt) { logEvents.push(evt); }), "logLevelTest"); log4js.addAppender(
logger = log4js.getLogger("logLevelTest"); require('../lib/appenders/logLevelFilter')
logger.debug('this should not trigger an event'); .appender(
logger.warn('neither should this'); 'ERROR',
logger.error('this should, though'); function(evt) { logEvents.push(evt); }
logger.fatal('so should this'); ),
return logEvents; "logLevelTest"
}, );
'should only pass log events greater than or equal to its own level' : function(logEvents) {
assert.equal(logEvents.length, 2); logger = log4js.getLogger("logLevelTest");
assert.equal(logEvents[0].data[0], 'this should, though'); logger.debug('this should not trigger an event');
assert.equal(logEvents[1].data[0], 'so should this'); logger.warn('neither should this');
} logger.error('this should, though');
logger.fatal('so should this');
return logEvents;
}, },
'should only pass log events greater than or equal to its own level' : function(logEvents) {
'configure': { assert.equal(logEvents.length, 2);
topic: function() { assert.equal(logEvents[0].data[0], 'this should, though');
var log4js = require('../lib/log4js') assert.equal(logEvents[1].data[0], 'so should this');
, logger;
remove(__dirname + '/logLevelFilter.log');
remove(__dirname + '/logLevelFilter-warnings.log');
log4js.configure('test/with-logLevelFilter.json');
logger = log4js.getLogger("tests");
logger.info('main');
logger.error('both');
logger.warn('both');
logger.debug('main');
//wait for the file system to catch up
setTimeout(this.callback, 100);
},
'tmp-tests.log': {
topic: function() {
fs.readFile(__dirname + '/logLevelFilter.log', 'utf8', this.callback);
},
'should contain all log messages': function(contents) {
var messages = contents.trim().split('\n');
assert.deepEqual(messages, ['main','both','both','main']);
}
},
'tmp-tests-warnings.log': {
topic: function() {
fs.readFile(__dirname + '/logLevelFilter-warnings.log','utf8',this.callback);
},
'should contain only error and warning log messages': function(contents) {
var messages = contents.trim().split('\n');
assert.deepEqual(messages, ['both','both']);
}
}
} }
},
'configure': {
topic: function() {
var log4js = require('../lib/log4js')
, logger;
remove(__dirname + '/logLevelFilter.log');
remove(__dirname + '/logLevelFilter-warnings.log');
log4js.configure('test/with-logLevelFilter.json');
logger = log4js.getLogger("tests");
logger.info('main');
logger.error('both');
logger.warn('both');
logger.debug('main');
//wait for the file system to catch up
setTimeout(this.callback, 100);
},
'tmp-tests.log': {
topic: function() {
fs.readFile(__dirname + '/logLevelFilter.log', 'utf8', this.callback);
},
'should contain all log messages': function(contents) {
var messages = contents.trim().split('\n');
assert.deepEqual(messages, ['main','both','both','main']);
}
},
'tmp-tests-warnings.log': {
topic: function() {
fs.readFile(__dirname + '/logLevelFilter-warnings.log','utf8',this.callback);
},
'should contain only error and warning log messages': function(contents) {
var messages = contents.trim().split('\n');
assert.deepEqual(messages, ['both','both']);
}
}
}
}).export(module); }).export(module);