logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 46851] New: DailyRollingFileAppender with DatePattern='.'yyyy-ww gives monthly log rotation if the default locale is Locale.GERMAN
Date Fri, 13 Mar 2009 15:36:07 GMT
https://issues.apache.org/bugzilla/show_bug.cgi?id=46851

           Summary: DailyRollingFileAppender with DatePattern='.'yyyy-ww
                    gives monthly log rotation if the default locale is
                    Locale.GERMAN
           Product: Log4j
           Version: 1.2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: PatchAvailable
          Severity: normal
          Priority: P2
         Component: Appender
        AssignedTo: log4j-dev@logging.apache.org
        ReportedBy: strozyk@adesso.de


Using the DailyRollingFileAppender with DatePattern='.'yyyy-ww gives monthly
log rotation if the default locale of the JVM is Locale.GERMAN.

Expected is weekly log rotation as documented in JavaDoc.


I think the reason for this issue is that in method
DailyRollingFileAppender.computeCheckPeriod:
-the RollingCalendar instance is explicitly constructed with Locale.ENGLISH,
which gives SUNDAY as first day of week
-in the SimpleDateFormat instance, only timezone is set. Therefore, in germany
simpleDateFormat uses a Calendar with Locale.GERMAN, which gives MONDAY as
first day of week
Then, rollingCalendar.getNextCheckMillis() returns a Sunday, which belongs to
the same week as epoch from SimpleDateFormat's point of view.

I suggest to fix the problem by removing -line and adding +lines as follows:

  int computeCheckPeriod() {
    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
+       // do all date formatting in GMT and with ENGLISH locale settings
+       Calendar formatCal = Calendar.getInstance(gmtTimeZone, Locale.ENGLISH);
+       simpleDateFormat.setCalendar(formatCal);
        String r0 ( https://svn.apache.org/viewcvs.cgi?view=rev&rev=0 )= simpleDateFormat.format(epoch);
        rollingCalendar.setType(i);
        Date next = new Date(rollingCalendar.getNextCheckMillis(epoch));
        String r1 ( https://svn.apache.org/viewcvs.cgi?view=rev&rev=1 )=  simpleDateFormat.format(next);
        //System.out.println("Type = "+i+", r0 ( https://svn.apache.org/viewcvs.cgi?view=rev&rev=0
)= "+r0 ( https://svn.apache.org/viewcvs.cgi?view=rev&rev=0 )", r1 ( https://svn.apache.org/viewcvs.cgi?view=rev&rev=1
)= "+r1 ( https://svn.apache.org/viewcvs.cgi?view=rev&rev=1 );
        if(r0 ( https://svn.apache.org/viewcvs.cgi?view=rev&rev=0 )!= null &&
r1 ( https://svn.apache.org/viewcvs.cgi?view=rev&rev=1 )!= null && !r0 ( https://svn.apache.org/viewcvs.cgi?view=rev&rev=0
)equals(r1 ( https://svn.apache.org/viewcvs.cgi?view=rev&rev=1 )) {
          return i;
        }
      }
    }
    return TOP_OF_TROUBLE; // Deliberately head for trouble...
  }

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


Mime
View raw message