1

我想通过 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>
4

1 回答 1

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> 
于 2013-04-18T20:47:13.130 回答