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

RobOaks roboaks at comcast.net
Thu Nov 29 14:33:30 CET 2012


In this case, I think it’s only partly me :-)
1.	With an <appender>/<file> element, the Logback debugging output warns me
that the log file rename failed and recommends I eliminate this element
(which works). For whatever reason, something in my environment is locking
the log file (preventing the Logback attempt to rename) while my app is
running. I can manually rename the file once my test program finishes
running.
2.	<maxHistory> is not having any effect and archive files are created ad
infinitum. I noticed a couple things: 1) the Logback debugging output
doesn’t indicate that this setting has been initialized, though this may be
normal. 2) Logback doesn’t indicate that it’s attempting to delete older log
files and failing; it’s simply silent, as if the maxHistory setting is
simply being ignored. I’m wondering if the problem could possibly have
something to do with the fact that I have two loggers that reference two
different appenders, both of which log to the same file (I do this because I
need the loggers to have two very different layout patterns; is there a way
to have an appender use a completely different layout pattern depending on
the logger? One of the layout patterns is “%-5level %logger{}.%method -
%msg%n" and the other is simply "%msg%n" so I don’t think evaluators can be
used). 


tony19 wrote:
> 
> 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
> 
> _______________________________________________
> Logback-user mailing list
> Logback-user at qos.ch
> http://mailman.qos.ch/mailman/listinfo/logback-user
> 

-- 
View this message in context: http://old.nabble.com/For-RollingFileAppender%2C-%3CrollingPolicy%3E-%3CfileNamePattern%3E-does-not-work-if-you-also-have-%3Cappender%3E-%3Cfile%3E-tp34729737p34737384.html
Sent from the Logback User mailing list archive at Nabble.com.



More information about the Logback-user mailing list