Details
-
Bug
-
Resolution: Fixed
-
Blocker
-
None
-
None
-
None
-
Operating System: Linux
Platform: All
-
80
Description
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; }
}
Attachments
Issue Links
- is duplicated by
-
LOGBACK-60 Time based logfile rotation does not log, uses 1970-01-01 as date
- Resolved