我从旧的(和不安全的)DailyRollingFileAppender切换到新的RollingFileAppender。所以现在我想测试我的配置但是我似乎无法触发翻转机制。 log4j检查哪一次决定翻转日志?我试着将系统时间设置回/将来,更改日志中的时间,更改文件时间......没有运气! 或者我的配置错了?
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="fileAppender" class="org.apache.log4j.rolling.RollingFileAppender">
<param name="file" value="some.log" />
<param name="append" value="true" />
<rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
<param name="FileNamePattern" value="%d.log" />
</rollingPolicy>
<layout class="org.apache.log4j.EnhancedPatternLayout">
<param name="ConversionPattern" value="[%d{dd.MM.yyyy HH:mm:ss,SSS}] [%-5p] %c - %m%n" />
</layout>
</appender>
...<!--appreviated for clarity-->
</log4j:configuration>
答案 0 :(得分:0)
阅读http://www.mail-archive.com/log4j-user@logging.apache.org/msg08183.html
DailyRollingFileAppender - Rotates based on dateFormat
RollingFileAppender - Rotates based on a maximum file size.
同时检查:
http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/RollingFileAppender.html
http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/DailyRollingFileAppender.html
自:
What is the difference between log4j RollingFileAppender vs DailyRollingFileAppender