[logback-user] For RollingFileAppender, <rollingPolicy>/<fileNamePattern> does not work if you also have <appender>/<file>

Tony Trinh tony19 at gmail.com
Wed Nov 28 04:40:49 CET 2012


On Tue, Nov 27, 2012 at 3:45 PM, RobOaks <roboaks at comcast.net> wrote:

>
> In addition to the problems I reported in my previous post (
>
> http://old.nabble.com/Config-file-failures-unexplained-in-list-or-JIRA-td34713039.html#a34713039
>
> http://old.nabble.com/Config-file-failures-unexplained-in-list-or-JIRA-td34713039.html#a34713039
> ) , I have found that, for the RollingFileAppender,
> <rollingPolicy>/<fileNamePattern> does not work if you also have
> <appender>/<file>. Here is the relevant section of my config file:
>
> <appender name="file"
> class="ch.qos.logback.core.rolling.RollingFileAppender">
>                 <file>Idcp.log</file>
>                 <rollingPolicy
> class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
>
> <fileNamePattern>%d{yyyy-MM-dd_HH-mm}_Idcp.log</fileNamePattern>
>                         <maxHistory>3</maxHistory>
>                 </rollingPolicy>
>                 <encoder>
>                         <pattern>%-5level %logger{}.%method - %msg%n
> </pattern>
>                 </encoder>
> </appender>
>
> With this configuration, all output goes to Idcp.log indefinitely, in spite
> of the fact that it should be creating an archive file every minute. As
> soon
> as I remove <file>Idcp.log</file>, active output is logged to a file of the
> form yyyy-MM-dd_HH-mm_Idcp.log and a new file is created every minute.
>
> But, even in the latter case, when archive files are being properly
> created,
> <maxHistory> is ignored and archive files are created ad infinitum.
>
> Is this a particularly buggy release of Logback? I’m really hoping it’s
> just
> me.
>
>
It might be just you. ;)

I used your configuration (from the original post) and modified
<fileNamePattern> to match your minute-rollover pattern. The file correctly
rolls over every minute for a maximum of 3 times, and the rollover files
are archived with the correct filename pattern that you specified. Note the
debug output at every minute in [1]. I log a message every second for 4
minutes (plus some padding to verify one complete rollover period beyond
the max), and logback correctly archives only 3 files.

[1] http://pastebin.com/6cr6NJSb
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/logback-user/attachments/20121127/21014257/attachment.html>


More information about the Logback-user mailing list