[logback-dev] [Bug 80] New: TimeBasedRollingPolicy do NOT work as expected

bugzilla-daemon at pixie.qos.ch bugzilla-daemon at pixie.qos.ch
Sun Jun 10 17:28:08 CEST 2007


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: logback-dev at qos.ch
        ReportedBy: eric.yung at jspectrum.com


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.



More information about the logback-dev mailing list