issue with RollingFileAppender when File matches FileNamePattern

Hello everyone! I've come across an issue with RollingFileAppender, but I'm not sure if it's us or logback. <configuration> <timestamp key="currentDate" datePattern="yyyy_MM_dd" /> <appender name="dataServiceRequestLog" class="ch.qos.logback.core.rolling.RollingFileAppender"> <param name="File" value="${the.log.dir}/${currentDate}.WebService.log"/> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <FileNamePattern>${the.log.dir}/%d{yyyy_MM_dd}.WebService.log</FileNamePattern> <MaxHistory>30</MaxHistory> </rollingPolicy> <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level - %msg%n</pattern> </encoder> </appender> The curious part is that File matches the FileNamePattern for the rolling policy ("${the.log.dir}/${currentDate}.WebService.log" and "${the.log.dir}/%d{yyyy_MM_dd}.WebService.log"). Do you guys think that's OK? The intention is that there's a separate file for every day: - 2013_01_03.WebService.log - 2013_01_04.WebService.log - 2013_01_05.WebService.log - 2013_01_06.WebService.log The issue we're experiencing is seemingly random writes to old log files (e.g., today we saw writes to 2013_01_04.WebService.log). Could this be the rename problem? Perhaps there's a better way to achieve the desired functionality. Is this worth writing a unit test for in RollingFileAppenderTest.java? Any tips are greatly appreciated, thanks!

Hi Karl, In this case, you can/should simply omit the file property. See [1]. HTH, -- Ceki 65% of statistics are made up on the spot [1] http://logback.qos.ch/manual/appenders.html#tbrpFileNamePattern On 08.01.2013 02:23, Karl Pietrzak wrote:
Hello everyone!
I've come across an issue with RollingFileAppender, but I'm not sure if it's us or logback.
<configuration>
<timestamp key="currentDate" datePattern="yyyy_MM_dd" />
<appender name="dataServiceRequestLog" class="ch.qos.logback.core.rolling.RollingFileAppender"> <param name="File" value="${the.log.dir}/${currentDate}.WebService.log"/> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <FileNamePattern>${the.log.dir}/%d{yyyy_MM_dd}.WebService.log</FileNamePattern> <MaxHistory>30</MaxHistory> </rollingPolicy> <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level - %msg%n</pattern> </encoder> </appender>
The curious part is that File matches the FileNamePattern for the rolling policy ("${the.log.dir}/${currentDate}.WebService.log" and "${the.log.dir}/%d{yyyy_MM_dd}.WebService.log").
Do you guys think that's OK? The intention is that there's a separate file for every day:
* 2013_01_03.WebService.log * 2013_01_04.WebService.log * 2013_01_05.WebService.log * 2013_01_06.WebService.log
The issue we're experiencing is seemingly random writes to old log files (e.g., today we saw writes to 2013_01_04.WebService.log). Could this be the rename problem?
Perhaps there's a better way to achieve the desired functionality. Is this worth writing a unit test for in RollingFileAppenderTest.java?
Any tips are greatly appreciated, thanks!

On 08.01.2013 13:44, Karl Pietrzak wrote:
Thanks for the reply, Ceki.
Do you think this would be causing the issues we're seeing? Or is it too difficult to tell?
File property and the archived files should not point to the same file path. When you wish them to point to the same path, then File property should be omitted. -- Ceki 65% of statistics are made up on the spot

On Tue, Jan 8, 2013 at 7:57 AM, ceki <ceki@qos.ch> wrote:
File property and the archived files should not point to the same file path. When you wish them to point to the same path, then File property should be omitted.
I agree... what are your thoughts on enforcing this through the code? I can submit a pull request with sanity check + a unit test, but I won't bother if you don't think it's worthwhile. Thanks!

On 08.01.2013 14:07, Karl Pietrzak wrote:
On Tue, Jan 8, 2013 at 7:57 AM, ceki <ceki@qos.ch <mailto:ceki@qos.ch>> wrote:
File property and the archived files should not point to the same file path. When you wish them to point to the same path, then File property should be omitted.
I agree... what are your thoughts on enforcing this through the code? I can submit a pull request with sanity check + a unit test, but I won't bother if you don't think it's worthwhile.
Such a sanity check + unit test would be most welcome. -- Ceki 65% of statistics are made up on the spot

On Tue, Jan 8, 2013 at 8:20 AM, ceki <ceki@qos.ch> wrote:
Such a sanity check + unit test would be most welcome.
Done! https://github.com/qos-ch/logback/pull/67 I'm just doing a simple regex match, so it's not a perfect check, but I figure it's better than nothing. Comments welcome. :)
participants (2)
-
ceki
-
Karl Pietrzak