DailyRollingFileAppender
在我的情况下也不起作用(在 log4cxx 0.10.0),所以我最终使用了RollingFileAppender
plus TimeBasedRollingPolicy
:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="roll" class="org.apache.log4j.rolling.RollingFileAppender">
<rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
<param name="FileNamePattern" value="roll.%d{yyyy-MM-dd}.log"/>
</rollingPolicy>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%p %t %c - %m%n"/>
</layout>
<param name="Append" value="true"/>
</appender>
<root>
<priority value="ALL"/>
<appender-ref ref="roll"/>
</root>
</log4j:configuration>
要点是不要指定<param name="file">
,否则它不会翻转(也不能StaticLogFileName
像原始 log4j 那样识别参数)。