你好,
在我们的 Web 应用程序中,它会打印所有的日志,就像 Spring 和 JSF jars 文件一样。这对我们来说不是必需的。如何在 log4j.xml 文件中设置为仅针对我们的应用程序进行过滤?
更新
以下是我们用于日志记录的配置。你能告诉我它是否正确吗?我必须在文件中的哪里添加记录器元素?
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<!-- Log4j Configuration file to log the messages into different logfiles -->
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="DEBUG" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="D:/logs/DEBUGFILE.log"/>
<param name="Append" value="true"/>
<param name="MaxFileSize" value="500KB"/>
<param name="MaxBackupIndex" value="2"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %p - %m%n"/>
</layout>
<filter class="org.apache.log4j.varia.LevelRangeFilter">
<param name="LevelMin" value="DEBUG" />
<param name="LevelMax" value="DEBUG" />
</filter>
</appender>
<appender name="INFO" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="D:/logs/AUDIT_TRAIL.log"/>
<param name="Append" value="true"/>
<param name="MaxFileSize" value="500KB"/>
<param name="MaxBackupIndex" value="2"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %p - %m%n"/>
</layout>
<filter class="org.apache.log4j.varia.LevelRangeFilter">
<param name="LevelMin" value="INFO" />
<param name="LevelMax" value="INFO" />
</filter>
</appender>
<appender name="ERROR" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="D:/logs/ERRORFILE.log"/>
<param name="Append" value="true"/>
<param name="MaxFileSize" value="500KB"/>
<param name="MaxBackupIndex" value="2"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %p - %m%n"/>
</layout>
<filter class="org.apache.log4j.varia.LevelRangeFilter">
<param name="LevelMin" value="ERROR" />
<param name="LevelMax" value="ERROR" />
</filter>
</appender>
<appender name="FATEL" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="D:/logs/FATELFILE.log"/>
<param name="Append" value="true"/>
<param name="MaxFileSize" value="500KB"/>
<param name="MaxBackupIndex" value="2"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %p - %m%n"/>
</layout>
<filter class="org.apache.log4j.varia.LevelRangeFilter">
<param name="LevelMin" value="FATAL" />
<param name="LevelMax" value="FATAL" />
</filter>
</appender>
<root>
<priority value="debug"/>
<appender-ref ref="DEBUG"/>
<appender-ref ref="INFO"/>
<appender-ref ref="ERROR"/>
<appender-ref ref="FATEL"/>
</root>
</log4j:configuration>