为了避免将日志输出到控制台,须将root元素中控制台的appender注释掉。
如:
<root>
<priority value ="debug" />
<appender-ref ref="console" />
</root>
需改成:
<root>
<priority value ="debug" />
<!--<appender-ref ref="console" />-->
</root>
完整log4j.xml配置如下:
<?xml version="1.0" encoding="GB2312" ?>
<!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="%d %-5p %x %m%n"/>
</layout>
</appender>
<appender name="system" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="d:/ServerHome/DatacheckHome/log/log.txt"/>
<param name="Append" value="true"/>
<param name="ImmediateFlush" value="true"/>
<param name="MaxFileSize" value="10MB"/>
<param name="MaxBackupIndex" value="50"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p %x %m%n"/>
</layout>
</appender>
<category name="org.apache">
<priority value="off" />
<appender-ref ref="console" />
</category>
<category name="com.apple">
<priority value="debug" />
<appender-ref ref="system" />
</category>
<root>
<priority value ="off" />
<!-- <appender-ref ref="console" /> -->
</root>
</log4j:configuration>
本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。