我在Log4J Extras中設置了一個TimeBasedRollingPolicy,我不清楚什麼時候告訴策略什麼時候翻身。 The API並不明確,所以我只是在做推論。這聽起來像是FileNamePattern中決定頻率的最後一個元素。什麼決定了log4j TimeBasedRollingPolicy何時翻轉?
拿這個例子從log4j Wiki:
<appender name="ROLL" class="org.apache.log4j.rolling.RollingFileAppender">
<!-- The active file to log to -->
<param name="file" value="/applogs/myportal/portal.log" />
<param name="append" value="true" />
<param name="encoding" value="UTF-8" />
<rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
<!-- The file to roll to, this is a fairly intelligent parameter, if the file
ends in .gz, it gzips it, based on the date stamp it rolls at that time,
default is yyyy-MM-dd, (rolls at midnight)
-->
<param name="FileNamePattern" value="/applogs/myportal/portal.%d.log.gz" />
</rollingPolicy>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%5p %d{ISO8601} [%t][%x] %c - %m%n" />
</layout>
</appender>
我是假設,因爲該模式dd中結束,該政策是把自己改變的時候?與API中的示例相同,「yyyy-MM」模式意味着文件在MM更改時應該滾動?
謝謝!
保羅
你是絕對正確的。我不知道爲什麼我沒有這樣做,但我檢查了[源代碼](https://svn.apache.org/repos/asf/logging/log4j/companions/extras/trunk/src/main/ java/org/apache/log4j/rolling/TimeBasedRollingPolicy.java)用於TimeBasedRollingPolicy,在翻轉邏輯中是註釋「如果文件名沒有改變,不翻轉」。謝謝! – Paul 2011-03-25 15:44:51