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

Ceki Gulcu commented on LBCORE-21:
----------------------------------

The link to revision 1917 was mistakenly associated with this bug. It should 
have been associated with LBCORE-26.


> TimeBasedRollingPolicy do NOT work as expected
> ----------------------------------------------
>
>                 Key: LBCORE-21
>                 URL: http://jira.qos.ch/browse/LBCORE-21
>             Project: logback-core
>          Issue Type: Bug
>          Components: Rolling
>    Affects Versions: unspecified
>         Environment: Operating System: Linux
> Platform: All
>            Reporter: Eric
>            Assignee: Logback dev list
>            Priority: Blocker
>
> When I use TimeBasedRollingPolicy as the rolling & triggering policy for the 
> RollingFileAppender, only the last log line appears in the new log file after 
> the 1st rolling trigger.
> The reason is that the TimeBasedRollingPolicy kept rolling for every log 
> event after the 1st rolling trigger. It causes by a bug in 
> isTriggeringEvent() method - the method uses the un-initialized value of 
> 'currentTime' (which is 0) to set the time of the 'lastCheck' Date object. 
> Original method :
> public boolean isTriggeringEvent(File activeFile, final Object event) {
>     //currentTime= System.currentTimeMillis();
>     if (getCurrentTime() >= nextCheck) {
>       //addInfo("Time to trigger roll-over");
>       // We set the elapsedPeriodsFileName before we set the 'lastCheck' 
> variable
>       // The elapsedPeriodsFileName corresponds to the file name of the period
>       // that just elapsed.
>       elapsedPeriodsFileName = activeFileNamePattern.convertDate(lastCheck);
>       //addInfo("elapsedPeriodsFileName set to "+elapsedPeriodsFileName);
>       lastCheck.setTime(currentTime);
>       nextCheck = rc.getNextCheckMillis(lastCheck);
>       
>       Date x = new Date();
>       x.setTime(nextCheck);
>       //addInfo("Next check on "+ x);
>       return true;
>     } else {
>       return false;
>     }
>   }
> Suggested Changes - uses a local long variable to store the value of 
> getCurrentTime() and uses it in the method for comparison and assignment:
>   public boolean isTriggeringEvent(File activeFile, final Object event) {
>     //currentTime= System.currentTimeMillis();
>     long  curT = getCurrentTime();
>     if (curT >= nextCheck) {
>       //addInfo("Time to trigger roll-over");
>       // We set the elapsedPeriodsFileName before we set the 'lastCheck' 
> variable
>       // The elapsedPeriodsFileName corresponds to the file name of the period
>       // that just elapsed.
>       elapsedPeriodsFileName = activeFileNamePattern.convertDate(lastCheck);
>       //addInfo("elapsedPeriodsFileName set to "+elapsedPeriodsFileName);
>       lastCheck.setTime(curT);
>       nextCheck = rc.getNextCheckMillis(lastCheck);
>       //Date x = new Date();
>       //x.setTime(nextCheck);
>       //addInfo("Next check on "+ x);
>       return true;
>     } else {
>       return false;
>     }
>   }

-- 
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

        
_______________________________________________
logback-dev mailing list
[email protected]
http://qos.ch/mailman/listinfo/logback-dev

Reply via email to