[logback-user] log rollover using %d multiple times in file name pattern?

Thomas Corte Thomas.Corte at knipp.de
Tue Dec 20 15:09:20 CET 2011


Hello,

I'm trying to configure a log rollover with logs being *rolled daily* 
and put into a directory named "yyyy-MM", i.e. one folder for each 
*month* containing that month's logs. I'm using the following appender 
config:

   <appender name="FILE" 
class="ch.qos.logback.core.rolling.RollingFileAppender">
     <file>app.log</file>

     <rollingPolicy 
class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
       <!-- rollover every minute -->
       <fileNamePattern%d{yyyy-MM}/app.%d{yyyy-MM-dd}.log</fileNamePattern>
     </rollingPolicy>

     <encoder>
       <pattern>%d{"yyyy-MM-dd HH:mm:ss,SSS"} [%thread] %-5level 
%logger{36} - %msg%n%xEx</pattern>
     </encoder>
   </appender>

However, it seems as if the current logback implementation merely 
considers the first %d specification, which leads to a log rotation only 
once per month instead of the desired once per day frequency.

I figure this is because via %d, the log rotation frequency and the file 
name pattern are somewhat tied together and seemingly can't be specified 
independently.

Is there any way to achieve what I'm trying to do without writing custom 
code?

Best regards,

Thomas

-- 
Thomas Corte
Thomas.Corte at knipp.de


More information about the Logback-user mailing list