proven that category filter no longer needed
This commit is contained in:
+79
-66
@@ -1,83 +1,96 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var vows = require('vows')
|
var async = require('async')
|
||||||
|
, should = require('should')
|
||||||
, fs = require('fs')
|
, fs = require('fs')
|
||||||
|
, path = require('path')
|
||||||
, assert = require('assert');
|
, assert = require('assert');
|
||||||
|
|
||||||
function remove(filename) {
|
function remove() {
|
||||||
try {
|
var files = Array.prototype.slice.call(arguments);
|
||||||
fs.unlinkSync(filename);
|
return function(done) {
|
||||||
} catch (e) {
|
async.forEach(
|
||||||
//doesn't really matter if it failed
|
files.map(function(file) { return path.join(__dirname, file); }),
|
||||||
}
|
fs.unlink.bind(fs),
|
||||||
|
function() { done(); }
|
||||||
|
);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
vows.describe('log4js categoryFilter').addBatch({
|
describe('log4js', function() {
|
||||||
'appender': {
|
|
||||||
topic: function() {
|
|
||||||
|
|
||||||
var log4js = require('../lib/log4js'), logEvents = [], webLogger, appLogger;
|
before(
|
||||||
log4js.clearAppenders();
|
remove(
|
||||||
var appender = require('../lib/appenders/categoryFilter')
|
'test-category-filter-web.log',
|
||||||
.appender(
|
'test-category-filter-all.log'
|
||||||
['app'],
|
)
|
||||||
function(evt) { logEvents.push(evt); }
|
);
|
||||||
);
|
|
||||||
log4js.addAppender(appender, ["app","web"]);
|
|
||||||
|
|
||||||
webLogger = log4js.getLogger("web");
|
after(
|
||||||
appLogger = log4js.getLogger("app");
|
remove(
|
||||||
|
'test-category-filter-web.log',
|
||||||
|
'test-category-filter-all.log'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
describe('category filtering', function() {
|
||||||
|
before(function() {
|
||||||
|
var log4js = require('../lib/log4js')
|
||||||
|
, webLogger = log4js.getLogger("web")
|
||||||
|
, appLogger = log4js.getLogger("app");
|
||||||
|
|
||||||
|
log4js.configure({
|
||||||
|
appenders: {
|
||||||
|
rest: {
|
||||||
|
type: "file",
|
||||||
|
layout: { type: "messagePassThrough" },
|
||||||
|
filename: path.join(__dirname, "test-category-filter-all.log")
|
||||||
|
},
|
||||||
|
web: {
|
||||||
|
type: "file",
|
||||||
|
layout: { type: "messagePassThrough"},
|
||||||
|
filename: path.join(__dirname, "test-category-filter-web.log")
|
||||||
|
}
|
||||||
|
},
|
||||||
|
categories: {
|
||||||
|
"default": { level: "debug", appenders: [ "rest" ] },
|
||||||
|
web: { level: "debug", appenders: [ "web" ] }
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
webLogger.debug('This should get logged');
|
webLogger.debug('This should get logged');
|
||||||
appLogger.debug('This should not');
|
appLogger.debug('This should not');
|
||||||
webLogger.debug('Hello again');
|
webLogger.debug('Hello again');
|
||||||
log4js.getLogger('db').debug('This shouldn\'t be included by the appender anyway');
|
log4js.getLogger('db').debug('This shouldn\'t be included by the appender anyway');
|
||||||
|
});
|
||||||
|
|
||||||
return logEvents;
|
it('should only pass matching category', function(done) {
|
||||||
},
|
setTimeout(function() {
|
||||||
'should only pass matching category' : function(logEvents) {
|
fs.readFile(
|
||||||
assert.equal(logEvents.length, 2);
|
path.join(__dirname, 'test-category-filter-web.log'),
|
||||||
assert.equal(logEvents[0].data[0], 'This should get logged');
|
'utf8',
|
||||||
assert.equal(logEvents[1].data[0], 'Hello again');
|
function(err, contents) {
|
||||||
}
|
var lines = contents.trim().split('\n');
|
||||||
},
|
lines.should.eql(["This should get logged", "Hello again"]);
|
||||||
|
done(err);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}, 50);
|
||||||
|
});
|
||||||
|
|
||||||
'configure': {
|
it('should send everything else to default appender', function(done) {
|
||||||
topic: function() {
|
setTimeout(function() {
|
||||||
var log4js = require('../lib/log4js')
|
fs.readFile(
|
||||||
, logger, weblogger;
|
path.join(__dirname, 'test-category-filter-all.log'),
|
||||||
|
'utf8',
|
||||||
|
function(err, contents) {
|
||||||
|
var lines = contents.trim().split('\n');
|
||||||
|
lines.should.eql(["This should not", "This shouldn't be included by the appender anyway"]);
|
||||||
|
done(err);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}, 50);
|
||||||
|
});
|
||||||
|
|
||||||
remove(__dirname + '/categoryFilter-web.log');
|
});
|
||||||
remove(__dirname + '/categoryFilter-noweb.log');
|
});
|
||||||
|
|
||||||
log4js.configure('test/with-categoryFilter.json');
|
|
||||||
logger = log4js.getLogger("app");
|
|
||||||
weblogger = log4js.getLogger("web");
|
|
||||||
|
|
||||||
logger.info('Loading app');
|
|
||||||
logger.debug('Initialising indexes');
|
|
||||||
weblogger.info('00:00:00 GET / 200');
|
|
||||||
weblogger.warn('00:00:00 GET / 500');
|
|
||||||
//wait for the file system to catch up
|
|
||||||
setTimeout(this.callback, 100);
|
|
||||||
},
|
|
||||||
'tmp-tests.log': {
|
|
||||||
topic: function() {
|
|
||||||
fs.readFile(__dirname + '/categoryFilter-noweb.log', 'utf8', this.callback);
|
|
||||||
},
|
|
||||||
'should contain all log messages': function(contents) {
|
|
||||||
var messages = contents.trim().split('\n');
|
|
||||||
assert.deepEqual(messages, ['Loading app','Initialising indexes']);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'tmp-tests-web.log': {
|
|
||||||
topic: function() {
|
|
||||||
fs.readFile(__dirname + '/categoryFilter-web.log','utf8',this.callback);
|
|
||||||
},
|
|
||||||
'should contain only error and warning log messages': function(contents) {
|
|
||||||
var messages = contents.trim().split('\n');
|
|
||||||
assert.deepEqual(messages, ['00:00:00 GET / 200','00:00:00 GET / 500']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}).export(module);
|
|
||||||
|
|||||||
Reference in New Issue
Block a user