log4j用properties文件配置,无法应用过滤器的解决方法

我用的log4j版本是1.2.16,在自定义Appender的时候需要用的过滤器来过滤某一区间等级的日志信息。然而配置很久properties文件仍然有错误

log4j:WARN Failed to set property [filter] to value "org.apache.log4j.varia.LevelRangeFilter".
log4j:ERROR Could not instantiate class [FATAL].

后来我在国外论坛上找到了答案

The PropertyConfigurator does not handle the advanced configuration features supported by the DOMConfigurator such as support for Filters, custom ErrorHandlers, nested appenders such as the AsyncAppender, etc.

 

翻译如下:

PropertyConfigurator 不能处理那些DOMConfigurator支持的高级配置功能,例如过滤器支持、自定义错误处理器、嵌套Appender(例如AsyncAppender)等等

 

看来xml配置才是log4j的王道。果然换了xml配置就可以使用了。

参考地址:http://stackoverflow.com/questions/1257641/cant-set-levelrangefilter-for-log4j

你可能感兴趣的:(log4j,xml,properties,filter,features,nested)