Thanks, I find the below segment from log4j manual
----Note that filtering is only supported by the DOMConfigurator. The PropertyConfigurator does not support filters. That's a reason for me to migrate from log4j.properties to log4j.xml.
(注:以下配置曾经修改,请参看原文)
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'>
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%m" />
</layout>
</appender>
<appender name="debug.file" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="app.debug.log" />
<param name="Append" value="false" />
<param name="Encoding" value="UTF-8" />
<param name="ImmediateFlush" value="true" />
<param name="MaxFileSize" value="1MB" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%m" />
</layout>
<filter class="org.apache.log4j.varia.LevelRangeFilter">
<param name="levelMin" value="DEBUG" />
<param name="levelMax" value="DEBUG" />
<param name="acceptOnMatch" value="true" />
</filter>
</appender>
<appender name="info.console" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%m" />
</layout>
<filter class="org.apache.log4j.varia.LevelRangeFilter">
<param name="levelMin" value="INFO" />
<param name="levelMax" value="FATAL" />
<param name="acceptOnMatch" value="false" />
</filter>
</appender>
<appender name="info.file" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="app.info.log" />
<param name="Append" value="true" />
<param name="ImmediateFlush" value="true" />
<param name="MaxFileSize" value="10MB" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%m" />
</layout>
<filter class="org.apache.log4j.varia.LevelRangeFilter">
<param name="levelMin" value="INFO" />
<param name="levelMax" value="INFO" />
<param name="acceptOnMatch" value="true" />
</filter>
</appender>
<logger name="net.alsan" additivity="false">
<level value="DEBUG" />
<appender-ref ref="debug.file" />
<appender-ref ref="info.console" />
</logger>
<root>
<level value="ERROR" />
<appender-ref ref="console" />
</root>
</log4j:configuration>