2013-06-04 06:17:36 +08:00
|
|
|
"use strict";
|
|
|
|
var levels = require('../levels')
|
|
|
|
, log4js = require('../log4js');
|
2011-07-24 19:58:02 +08:00
|
|
|
|
2014-08-26 01:48:15 +08:00
|
|
|
function logLevelFilter (minLevelString, maxLevelString, appender) {
|
|
|
|
var minLevel = levels.toLevel(minLevelString);
|
|
|
|
var maxLevel = levels.toLevel(maxLevelString, levels.FATAL);
|
2013-06-04 06:17:36 +08:00
|
|
|
return function(logEvent) {
|
2014-08-26 01:48:15 +08:00
|
|
|
var eventLevel = logEvent.level;
|
|
|
|
if (eventLevel.isGreaterThanOrEqualTo(minLevel) && eventLevel.isLessThanOrEqualTo(maxLevel)) {
|
2013-06-04 06:17:36 +08:00
|
|
|
appender(logEvent);
|
2011-07-24 19:58:02 +08:00
|
|
|
}
|
2013-06-04 06:17:36 +08:00
|
|
|
};
|
2011-07-24 19:58:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function configure(config) {
|
2013-06-04 06:17:36 +08:00
|
|
|
log4js.loadAppender(config.appender.type);
|
|
|
|
var appender = log4js.appenderMakers[config.appender.type](config.appender);
|
2014-08-26 01:48:15 +08:00
|
|
|
return logLevelFilter(config.level, config.maxLevel, appender);
|
2011-07-24 19:58:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
exports.appender = logLevelFilter;
|
2011-10-27 13:37:11 +08:00
|
|
|
exports.configure = configure;
|