[logback-dev] [JIRA] Commented: (LBCORE-242) log rollover should be configurable using %d multiple times in file name pattern

Ceki Gulcu (JIRA) noreply-jira at qos.ch
Wed Dec 21 11:53:12 CET 2011


    [ http://jira.qos.ch/browse/LBCORE-242?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12336#action_12336 ] 

Ceki Gulcu commented on LBCORE-242:
-----------------------------------

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 is more flexible as it allows for patterns with higher precision. For example, for a daily rollover period, you could have %d{yyyy-MM-dd'T'HH_mm} as the pattern (precise to the minute). I don't see such flexibility as being useful. As such, safety trumps flexibility in this case. 

I've considered two possible solutions to this problem:

First solution: add an option, say AUX (for auxiliary), to %d so that the token is *not* taken into account when determining the rollover period.

you would write:
 <fileNamePattern>%d{yyyy-MM, aux}/app.%d{yyyy-MM-dd}.log</fileNamePattern>

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. It has been implemented in [1] and [2] 

[1] http://github.com/ceki/logback/commit/0fe93ab5
[2] http://github.com/ceki/logback/commit/7900adbe



> log rollover should be configurable using %d multiple times in file name pattern
> --------------------------------------------------------------------------------
>
>                 Key: LBCORE-242
>                 URL: http://jira.qos.ch/browse/LBCORE-242
>             Project: logback-core
>          Issue Type: Improvement
>          Components: Rolling
>    Affects Versions: 1.0.0
>            Reporter: Thomas Corte
>            Assignee: Ceki Gulcu
>
> 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:
> {noformat}
>   <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>
> {noformat}
> 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.
> It would be nice if either multiple %d specifiers would be supported, with an option to specify which one should be considered for the rollover period.
> Even better, it might be a good idea to support the rollover period to be specified separately and independently from the file name pattern; arguably, using the file name patterns for both is somewhat convenient, but violates the principle of "separation of concerns".

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.qos.ch/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the logback-dev mailing list