我想通过xml配置log4cxx,以便每分钟滚动我的日志文件。我尝试使用以下log4j.xml文件,但它似乎有时只是随机工作。我还尝试使用TimeBasedRollingPolicy的另一个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="appxRollingAppenderDaily" class="org.apache.log4j.rolling.RollingFileAppender">
<rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
<param name="FileNamePattern" value="TimeBasedLog.%d{yyyy-MM-dd-HH-mm}.log"/>
<param name="activeFileName" value="appxDailyLog.log"/>
</rollingPolicy>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss,SSS} %x [%p] (%F:%L) %m%n"/>
</layout>
<param name="file" value="appxDailyLog.log"/>
<param name="append" value="true"/>
</appender>
<root>
<priority value="all" />
<appender-ref ref="appxRollingAppenderDaily"/>
</root>
</log4j:configuration>
答案 0 :(得分:0)
试试这个:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="appxRollingAppenderDaily" class="org.apache.log4j.DailyRollingFileAppender">
<param name="Threshold" value="ALL"/>
<param name="file" value="./appxDailyLog.log"/>
<param name="DatePattern" value="'.'yyyy-MM-dd" />
<layout class="org.apache.log4j.PatternLayout">
<!-- <param name="ConversionPattern" value="%p %t %c - %m%n"/> -->
<!-- <param name="ConversionPattern" value="%d{ISO8601} [%15.15t] %-5p %l - %m%n"/> -->
<!-- <param name="ConversionPattern" value="%d{ISO8601} [%-8.8t] %-5p (%t) - %m%n"/> -->
<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss,SSS} %x [%p] (%F:%L) %m%n"/>
</layout>
</appender>
<root>
<priority value="ALL" />
<appender-ref ref="appxRollingAppenderDaily"/>
</root>
</log4j:configuration>