Category excluding filter.
This filtering appender allows you to choose some category names that won't be logged to the delegated appender. This is useful if you have e.g. a category that you use to log web requests to one file, but want to keep those entries out of the main log file without having to explicitly list all the other categories that you _do_ want to include. Has one option, "exclude", which is a category name or array of category names. The child appender is set in "appender", modelled on the logLevelFilter.
This commit is contained in:
24
lib/appenders/categoryFilter.js
Normal file
24
lib/appenders/categoryFilter.js
Normal file
@@ -0,0 +1,24 @@
|
||||
var levels = require('../levels');
|
||||
var log4js = require('../log4js');
|
||||
|
||||
function contains(list, value) {
|
||||
return list.indexOf(value) !== -1;
|
||||
}
|
||||
|
||||
function categoryFilter (excludes, appender) {
|
||||
if (typeof(excludes) === 'string') excludes = [excludes];
|
||||
return function(logEvent) {
|
||||
if (excludes.indexOf(logEvent.categoryName) === -1) {
|
||||
appender(logEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function configure(config) {
|
||||
log4js.loadAppender(config.appender.type);
|
||||
var appender = log4js.appenderMakers[config.appender.type](config.appender);
|
||||
return categoryFilter(config.exclude, appender);
|
||||
}
|
||||
|
||||
exports.appender = categoryFilter;
|
||||
exports.configure = configure;
|
||||
Reference in New Issue
Block a user