[logback-dev] TimeBasedRollingPolicy is bogus

Szel, Zoltan Zoli.Szel at MorganStanley.com
Tue Jul 14 15:35:33 CEST 2009


Hi all,

This issue is quite long outstanding and I did not see any progress on it so far so I thought it might be worthwhile to rise this issue again(http://jira.qos.ch/browse/LBCORE-61).

Basically what happens here is, that if you use any other triggering policy together with the TimeBasedRollingPolicy than your application will die with an exception. The use case is fairly common for this kind of feature for example I want to get my log files rotated and I want to see when that rotation happened.

The root cause of this problem lies in the isTriggeringEvent() method. That method is responsible for setting the elapsedPeriodsFileName variable(besides telling logback whether we have to trigger or not). When the TimeBasedRollingPolicy is used with other triggering policy, the isTriggeringEvent() method is not called hence the elapsedPeriodsFileName is null hence a an NPE. This can be easily fixed by letting the TimeBasedRollingPolicy to calculate the elapsedPeriodsFileName when it is not set yet already:

Public void rollover() throws RolloverFailure{
                If(elapsedPeriodsFileName==null){
                                elapsedPeriodsFileName = activeFileNamePattern.convertDate(new Date(getTime()));
}
Try{
     //rest of the rollover method
}
Finally{
   elapsedPeriodsFileName=null
}
}

With this fix in place a lot more features can be added easily to the rotating space:


1)      Rotating on multiple criteria(rotate my files at midnight  or when it reaches 1G)( http://jira.qos.ch/browse/LBCORE-60)

2)      Rotate on restart(http://jira.qos.ch/browse/LBCORE-91)

3)      The already mentioned rotate on file size but put timestamp on the files

For 1 and 2 we will need a new triggering policy which is an affirmative triggering policy making decisions based on other triggering policies set on it. With this new triggering policy 1 can be reached by specifying a size based triggering policy and a timebased rolling policy as triggering policies. For 2 a new triggering policy should be created which will say yes on the first call to isTriggeringEvent and will say no on every subsequent call.

Hope I made my point clear and you guys can make this small change.
Thanks for your help in advance,

Regards
Zoltan Szel
Morgan Stanley | IDEAS Practice Areas
Lechner Odon fasor 8 | Floor 07
Budapest, 1095
Phone: +36 1 881-3978
Zoli.Szel at MorganStanley.com<mailto:Zoli.Szel at MorganStanley.com>

--------------------------------------------------------------------------
NOTICE: If received in error, please destroy, and notify sender. Sender does not intend to waive confidentiality or privilege. Use of this email is prohibited when received in error. We may monitor and store emails to the extent permitted by applicable law.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://qos.ch/pipermail/logback-dev/attachments/20090714/0c08821d/attachment.htm>


More information about the logback-dev mailing list