cvs commit: jakarta-log4j/src/java/org/apache/log4j DailyRollingFileAppender.java

[email protected] 9 May 2002 10:25:18 -0000
Newsgroups gmane.comp.jakarta.log4j.cvs
Message-ID <[email protected]>
ceki        02/05/09 03:25:18

  Modified:    src/java/org/apache/log4j DailyRollingFileAppender.java
  Log:
   Fixed a problem with DailiyRollingAppender which would not
   correctly compute the rollover period in certain timezones. [*]
  
  Revision  Changes    Path
  1.20      +21 -3     jakarta-log4j/src/java/org/apache/log4j/DailyRollingFileAppender.java
  
  Index: DailyRollingFileAppender.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/DailyRollingFileAppender.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- DailyRollingFileAppender.java	24 Apr 2002 01:16:14 -0000	1.19
  +++ DailyRollingFileAppender.java	9 May 2002 10:25:18 -0000	1.20
  @@ -15,6 +15,8 @@
   import java.util.Date;
   import java.util.GregorianCalendar;
   import java.util.Calendar;
  +import java.util.TimeZone;
  +import java.util.Locale;
   
   import org.apache.log4j.helpers.LogLog;
   import org.apache.log4j.spi.LoggingEvent;
  @@ -158,6 +160,10 @@
   
     int checkPeriod = TOP_OF_TROUBLE;
   
  +
  +  static final TimeZone gmtTimeZone = TimeZone.getTimeZone("GMT");
  +
  +
     /**
        The default constructor does nothing. */
     public
  @@ -245,16 +251,20 @@
     // This method computes the roll over period by looping over the
     // periods, starting with the shortest, and stopping when the r0 is
     // different from from r1, where r0 is the epoch formatted according
  -  // the datePattern and r1 is the epoch+nextMillis(i) formatted
  -  // according to the datePattern.
  +  // the datePattern (supplied by the user) and r1 is the
  +  // epoch+nextMillis(i) formatted according to datePattern. All date
  +  // formatting is done in GMT and not local format because the test
  +  // logic is based on comparisons relative to 1970-01-01 00:00:00
  +  // GMT (the epoch).
   
     int computeCheckPeriod() {
  -    RollingCalendar rollingCalendar = new RollingCalendar();
  +    RollingCalendar rollingCalendar = new RollingCalendar(gmtTimeZone, Locale.ENGLISH);
       // set sate to 1970-01-01 00:00:00 GMT
       Date epoch = new Date(0);
       if(datePattern != null) {
         for(int i = TOP_OF_MINUTE; i <= TOP_OF_MONTH; i++) {
   	SimpleDateFormat simpleDateFormat = new SimpleDateFormat(datePattern);
  +	simpleDateFormat.setTimeZone(gmtTimeZone); // do all date formatting in GMT
   	String r0 = simpleDateFormat.format(epoch);
   	rollingCalendar.setType(i);
   	Date next = new Date(rollingCalendar.getNextCheckMillis(epoch));
  @@ -348,6 +358,14 @@
   class RollingCalendar extends GregorianCalendar {
   
     int type = DailyRollingFileAppender.TOP_OF_TROUBLE;
  +
  +  RollingCalendar() {
  +    super();
  +  }  
  +
  +  RollingCalendar(TimeZone tz, Locale locale) {
  +    super(tz, locale);
  +  }  
   
     void setType(int type) {
       this.type = type;