I'm trying to achieve with logback the same thing that currently works with log4j - a size and time base rolling file appender. Upon rolling a new file should be created with the current timestamp but logback still writes to the old file.
I'm using something like:
<timestamp key="bySecond" datePattern="yyyyMMddkkmmss"/>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${logback.PREFIX}-${bySecond}.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${logback.PREFIX}-%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>1GB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
Wanted behaviour:
Current behavior:
It would be nice if I would also find out how to have this done only on the day rollover and not on the size, but this could be enough.
Java 1.7 with logback-1.0.9
I am not sure but let me try to resolve it. Once the rolling event occurred, the content of "my-20131206105823.log" file get copied to "my-2013-12-06.0.log.gz" and you will again get the new file with the same old name i,e "my-20131206105823.log".
<file>${logback.PREFIX}-${bySecond}.log</file>
$bySecond get assigned just once when you start your application, It won't change on every rollback. Timestamp is just a variable. Check here
Also check this one .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.