http://bugzilla.qos.ch/show_bug.cgi?id=80
Summary: TimeBasedRollingPolicy do NOT work as expected
Product: logback-core
Version: unspecified
Platform: All
OS/Version: Linux
Status: NEW
Severity: blocker
Priority: P1
Component: Rolling
AssignedTo: [email protected]
ReportedBy: [EMAIL PROTECTED]
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;
}
}
--
Configure bugmail: http://bugzilla.qos.ch/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
_______________________________________________
logback-dev mailing list
[email protected]
http://qos.ch/mailman/listinfo/logback-dev