I would like to roll a log after either one minute elapsed or 1MB size exceeded. But with the below configuration, only the first log is created taking the size in regard. Lets say:
myapp.2012-11-21_15-07.log (size:1026KB – 1MB)
myapp.log (size: 89KB)
Lets say that time passes (but we are still within that minute) and the log gets filled (exceeds 1MB), it won’t create another file. Another file is only created when the time is exceeded with no regard to the size.
Is this a bug or the intended feature? How do I configure this using logback? Do I need a custom implementation?
as much as I read in the current manual when I want a log rolled after either one minute elapsed or 1MB size exceeded, I would do the following configuration:
<configuration>
<appender name="file"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${catalina.base}/logs/myapp.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${catalina.base}/logs/myapp.%d{yyyy-MM-dd_HH-mm}.log</fileNamePattern>
<maxHistory>90</maxHistory>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>1MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<encoder>
<pattern>%-5level %date{ISO8601} [%thread]: [%class: %method] %message%n</pattern>
</encoder>
</appender>
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%-5level %date{ISO8601} [%thread]: [%class: %method] %message%n</pattern>
</encoder>
</appender>
</appender>
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%-5level %date{ISO8601} [%thread]: [%class: %method] %message%n</pattern>
</encoder>
</appender>
<logger name="org.springframework.core">
<level value="all"/>
</logger>
<logger name="org.springframework.beans">
<level value="all"/>
</logger>
<logger name="org.springframework.context">
<level value="all"/>
</logger>
<logger name="org.springframework.web">
<level value="all"/>
</logger>
<root level="error,info,debug">
<appender-ref ref="file"/>
<!-- <appender-ref ref="console"/> -->
</root>
</configuration>
The dependencies (I’m excluding commons-logging in each dependency that is using it to gain the power of logback – not shown below):
<!-- LOGGING -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.6</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.6.6</version>
</dependency>
<!--END LOGGING-->
Some additional info:
I also tried the 1.0.7 version (the last one although not available through the central repository – had to manually include it in the local maven repository), but the same happened.
My project was using 0.9.11 version of logback and I couldn’t set up a rolling policy cause I couldn’t find any valid documentation/manual. Perhaps someone could also point out some old manuals for those who need to work with legacy dependencies.
Kind Regards,
despot
You have to set the rolling policy to use SizeAndTimeBasedFNATP
Here is the documentation with an example
http://logback.qos.ch/manual/appenders.html#SizeAndTimeBasedFNATP
You are missing the %i:
Note the “%i” conversion token in addition to “%d”. Each time the current log file reaches maxFileSize before the current time period ends, it will be archived with an increasing index, starting at 0.