log rollover using %d multiple times in file name pattern?

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@knipp.de

Hi Thomas, See inline response. On 20.12.2011 15:09, Thomas Corte wrote:
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.
Yes, currently only the first %d token determines the rolling period.
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?
I've started working on this problem. Can you please enter a bug report requesting this future along the lines of your email post? It makes referencing easier. Here are some possible solutions. First solution: add an option, say SECONDARY, to %d so that the token is *not* taken into account when determining the rollover period. you would write: <FileNamePattern>%d{yyyy-MM,SECONDARY}/app.%d{yyyy-MM-dd}.log</File...> Second solution: use a different identifier for the token, for example %t instead of %d. you would write: <FileNamePattern>%t{yyyy-MM}/app.%d{yyyy-MM-dd}.log</FileNamePattern> I have a slight preference for the first solution because it involves less code changes.
Best regards,
Thomas
-- Ceki http://twitter.com/#!/ceki

Hi Ceki, On 20.12.2011 16:36, ceki wrote:
I've started working on this problem. Can you please enter a bug report requesting this future along the lines of your email post? It makes referencing easier.
Thanks for the quick reply. I just created http://jira.qos.ch/browse/LBCORE-242 to cover this.
Here are some possible solutions.
First solution: add an option, say SECONDARY, to %d so that the token is *not* taken into account when determining the rollover period.
you would write: <FileNamePattern>%d{yyyy-MM,SECONDARY}/app.%d{yyyy-MM-dd}.log</File...>
Second solution: use a different identifier for the token, for example %t instead of %d.
you would write: <FileNamePattern>%t{yyyy-MM}/app.%d{yyyy-MM-dd}.log</FileNamePattern>
I have a slight preference for the first solution because it involves less code changes.
I guess both will get the job done, though the 2nd solution seems a little less kludgy to me. That said, it could be argued that using the file name pattern for specifying both, file names and the rollover period, is somewhat convenient, but violates the principle of "separation of concerns" to some extent. A dedicated (optional) property to specify the rollover period separately may be the best solution. But of course it's your call. Best regards, Thomas -- Thomas Corte Thomas.Corte@knipp.de

On 21.12.2011 11:13, Thomas Corte wrote:
That said, it could be argued that using the file name pattern for specifying both, file names and the rollover period, is somewhat convenient, but violates the principle of "separation of concerns" to some extent. A dedicated (optional) property to specify the rollover period separately may be the best solution. But of course it's your call.
Inferring the period from the file name pattern is less error prone. It is impossible to specify a shorter period than what the pattern can cater for. For example, when the period and the period are separate, it is possible to specify daily rollover for the pattern "%d{yyyy}.log" which would cause log archives to be clobbered on a daily basis. Inferring the period from the pattern avoid this problem. On the other hand, separation allows for patterns with better prevision. For example, for a daily rollover period, you could have %d{yyyy-MM-dd'T'HH_mm} as the pattern. I don't see such flexibility as being useful. As such, safety trumps flexibility in this case. -- Ceki http://twitter.com/#!/ceki

On 21.12.2011 11:39, ceki wrote:
On the other hand, separation allows for patterns with better prevision.
I meant to write: On the other hand, separation is more flexible as it allows for patterns with higher precision. -- Ceki http://twitter.com/#!/ceki
participants (2)
-
ceki
-
Thomas Corte