我想设置我的log4j.xml文件以在DEBUG级别记录特定的类/包,其余的在ERROR级别。
如下所示,我将日志记录级别更新为gov.xxxx.app.batch.thread
和gov.xxxx.app.batch.sms.DoWork
的信息。
然而,看起来threshold
优先(这是有道理的)。
有没有办法使类/包级别配置优先于阈值?或者另一种可以产生预期结果的方法?
的log4j.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration>
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<param name="threshold" value="all"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="conversionPattern" value="%d %p %c %L - %m%n"/>
</layout>
</appender>
<appender name="logFile" class="org.apache.log4j.DailyRollingFileAppender">
<param name="file" value="${app.batchdriver.home}/logs/${app.batchdriver.log.name}"/>
<param name="maxFileSize" value="5MB"/>
<param name="maxBackupIndex" value="20"/>
<param name="threshold" value="error"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="conversionPattern" value="%d %p %c %L - %m%n"/>
</layout>
</appender>
<!-- Logger for Batch classes -->
<logger name="gov.xxxx.app">
<level value="error"/>
</logger>
<!-- Logger for Spring classes -->
<logger name="org.springframework">
<level value="error"/>
</logger>
<!-- Logger for Hibernate classes -->
<logger name="org.hibernate">
<level value="error"/>
</logger>
<!-- Logger for Apache classes -->
<logger name="org.apache">
<level value="error"/>
</logger>
<!-- Logger for Apache classes -->
<logger name="net.sf">
<level value="error"/>
</logger>
<!-- Logger for testing Performance -->
<logger name="gov.xxxx.app.batch.thread">
<level value="info"/>
</logger>
<logger name="gov.xxxx.app.batch.sms.DoWork">
<level value="info"/>
</logger>
<root>
<priority value ="all" />
<appender-ref ref="console"/>
<appender-ref ref="logFile"/>
</root>
</log4j:configuration>
答案 0 :(得分:0)
如果我正确理解您的要求,您需要记录:
如果是这种情况,您需要执行以下操作:
<appender-ref ref="logFile"/>
,因为root logger指定&#34; all&#34;而且你不想那样