Can't set LevelRangeFilter for log4j

2019-07-20 08:29发布

问题:

I am using this property file to setup log4j in Spring:

log4j.appender.EMAIL=org.apache.log4j.net.SMTPAppender
log4j.appender.EMAIL.filter=org.apache.log4j.varia.LevelRangeFilter
log4j.appender.EMAIL.filter.levelMin=FATAL

but getting:

log4j:WARN Failed to set property [filter] to value "org.apache.log4j.varia.LevelRangeFilter". 

Any ideas?

回答1:

From the docs for PropertyConfigurator:

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.

I suggest you use an XML file to set it up instead.



回答2:

You don't need a filter for this.

log4j.appender.EMAIL.Threshold=FATAL