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 40888] New: - Weekly rotation problem in Europe
Date Fri, 03 Nov 2006 15:17:06 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG·
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=40888>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND·
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=40888

           Summary: Weekly rotation problem in Europe
           Product: Log4j
           Version: 1.2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: major
          Priority: P2
         Component: Appender
        AssignedTo: log4j-dev@logging.apache.org
        ReportedBy: czegledi.laszlo@freemail.hu


I have a problem using DailyRollingFileAppender with weekly rotation.
The problem is that the appender rolls over every month instead of every week.
The date pattern is:
log4j.appender.A1.DatePattern='.'yyyy-ww
log4j.appender.A1=org.apache.log4j.DailyRollingFileAppender

Log4j version: 1.2.14, java 1.5.0_06-b05 on Fedora Core 5.

OS environment settings:
LANG=hu_HU
TZ=Europe/Budapest


I debugged the DailyRollingFileAppender and found that when determining the
rotation period, method computeCheckPeriod() returns TOP_OF_MONTH instead of
TOP_OF_WEEK. 
The cause probably is that the getFirstDayOfWeek() call in
RollingCalendar.getNextCheckDate() returns Sunday instead of Monday as it should
in Hungary and in most part of Europe. Because the epoch and the first Sunday
after the epoch are on the same week, the method computeCheckPeriod() advances
to the next period type, monthly rotation.
Replacing getFirstDayOfWeek() with Calendar.getInstance().getFirstDayOfWeek()
resolves the problem for us.

This simple test program logs the week number within the current year, and the
log should be rotates when a new week starts (if you change the system time).
 
import java.util.GregorianCalendar;
import org.apache.log4j.Logger;

public class LogTest 
{
  private static final Logger log = Logger.getLogger(LogTest.class);
  
  public static void main(String args[]) 
  {
      GregorianCalendar cal = new GregorianCalendar();
      System.out.println("Sunday: " + cal.SUNDAY);
      System.out.println("Monday: " + cal.MONDAY);
      System.out.println("First day: " + cal.getFirstDayOfWeek());
      System.out.println("TimeZone: " + cal.getTimeZone().getDisplayName());
      try {
          for(int i = 0; i < 100;i++) {
              cal = new GregorianCalendar();
              log.warn("Hello, " + "week number: " + cal.get(cal.WEEK_OF_YEAR));
              Thread.currentThread().sleep(10 * 1000); // sleep 10 seconds
              System.out.println(i);
          }
      }
      catch(Exception ex) { log.error(ex); }
  }
} 


I tested with the following settings and got the same result:
LANG=en_GB
TZ=Europe/London

Thanks,
Laszlo

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

---------------------------------------------------------------------
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