markt 2005/03/28 11:06:38 Modified: catalina/src/share/org/apache/catalina/valves AccessLogValve.java FastCommonAccessLogValve.java webapps/docs changelog.xml Log: Fix bug 20380. Timezone reported in access log should include any adjustment necesary for Daylight Saving Time. Ported from TC4. Revision Changes Path 1.15 +43 -16 jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/valves/AccessLogValve.java Index: AccessLogValve.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/valves/AccessLogValve.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- AccessLogValve.java 23 Dec 2004 23:58:07 -0000 1.14 +++ AccessLogValve.java 28 Mar 2005 19:06:38 -0000 1.15 @@ -25,6 +25,7 @@ import java.net.InetAddress; import java.text.DecimalFormat; import java.text.SimpleDateFormat; +import java.util.Calendar; import java.util.Date; import java.util.TimeZone; @@ -263,12 +264,26 @@ /** - * The time zone relative to GMT. + * The system timezone. */ - private String timeZone = null; + private TimeZone timezone = null; + + + /** + * The time zone offset relative to GMT in text form when daylight saving + * is not in operation. + */ + private String timeZoneNoDST = null; /** + * The time zone offset relative to GMT in text form when daylight saving + * is in operation. + */ + private String timeZoneDST = null; + + + /** * The system time when we last updated the Date that this valve * uses for log lines. */ @@ -557,15 +572,15 @@ } result.append("["); - result.append(dayFormatter.format(date)); // Day + result.append(dayFormatter.format(date)); // Day result.append('/'); result.append(lookup(monthFormatter.format(date))); // Month result.append('/'); - result.append(yearFormatter.format(date)); // Year + result.append(yearFormatter.format(date)); // Year result.append(':'); - result.append(timeFormatter.format(date)); // Time + result.append(timeFormatter.format(date)); // Time result.append(space); - result.append(timeZone); // Time Zone + result.append(getTimeZone(date)); // Time Zone result.append("] \""); result.append(request.getMethod()); @@ -858,7 +873,7 @@ temp.append(':'); temp.append(timeFormatter.format(date)); // Time temp.append(' '); - temp.append(timeZone); // Timezone + temp.append(getTimeZone(date)); // Timezone temp.append(']'); value = temp.toString(); } else if (pattern == 'T') { @@ -977,6 +992,15 @@ } + private String getTimeZone(Date date) { + if (timezone.inDaylightTime(date)) { + return timeZoneDST; + } else { + return timeZoneNoDST; + } + } + + private String calculateTimeZoneOffset(long offset) { StringBuffer tz = new StringBuffer(); if ((offset<0)) { @@ -1057,21 +1081,24 @@ started = true; // Initialize the timeZone, Date formatters, and currentDate - TimeZone tz = TimeZone.getDefault(); - timeZone = calculateTimeZoneOffset(tz.getRawOffset()); - + timezone = TimeZone.getDefault(); + timeZoneNoDST = calculateTimeZoneOffset(timezone.getRawOffset()); + Calendar calendar = Calendar.getInstance(timezone); + int offset = calendar.get(Calendar.DST_OFFSET); + timeZoneDST = calculateTimeZoneOffset(timezone.getRawOffset()+offset); + if (fileDateFormat==null || fileDateFormat.length()==0) fileDateFormat = "yyyy-MM-dd"; dateFormatter = new SimpleDateFormat(fileDateFormat); - dateFormatter.setTimeZone(tz); + dateFormatter.setTimeZone(timezone); dayFormatter = new SimpleDateFormat("dd"); - dayFormatter.setTimeZone(tz); + dayFormatter.setTimeZone(timezone); monthFormatter = new SimpleDateFormat("MM"); - monthFormatter.setTimeZone(tz); + monthFormatter.setTimeZone(timezone); yearFormatter = new SimpleDateFormat("yyyy"); - yearFormatter.setTimeZone(tz); + yearFormatter.setTimeZone(timezone); timeFormatter = new SimpleDateFormat("HH:mm:ss"); - timeFormatter.setTimeZone(tz); + timeFormatter.setTimeZone(timezone); currentDate = new Date(); dateStamp = dateFormatter.format(currentDate); timeTakenFormatter = new DecimalFormat("0.000"); 1.2 +38 -12 jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/valves/FastCommonAccessLogValve.java Index: FastCommonAccessLogValve.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/valves/FastCommonAccessLogValve.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- FastCommonAccessLogValve.java 25 Oct 2004 15:29:12 -0000 1.1 +++ FastCommonAccessLogValve.java 28 Mar 2005 19:06:38 -0000 1.2 @@ -24,6 +24,7 @@ import java.io.IOException; import java.io.PrintWriter; import java.text.SimpleDateFormat; +import java.util.Calendar; import java.util.Date; import java.util.TimeZone; @@ -207,9 +208,22 @@ /** - * The time zone relative to GMT. + * The system timezone. */ - private String timeZone = null; + private TimeZone timezone = null; + + + /** + * The time zone offset relative to GMT in text form when daylight saving + * is not in operation. + */ + private String timeZoneNoDST = null; + + /** + * The time zone offset relative to GMT in text form when daylight saving + * is in operation. + */ + private String timeZoneDST = null; /** @@ -677,7 +691,7 @@ result.append(timeFormatter.format(date)); result.append(space); // Time zone - result.append(timeZone); + result.append(getTimeZone(date)); result.append("] \""); // Check for log rotation @@ -705,6 +719,15 @@ } + private String getTimeZone(Date date) { + if (timezone.inDaylightTime(date)) { + return timeZoneDST; + } else { + return timeZoneNoDST; + } + } + + private String calculateTimeZoneOffset(long offset) { StringBuffer tz = new StringBuffer(); if ((offset<0)) { @@ -785,21 +808,24 @@ started = true; // Initialize the timeZone, Date formatters, and currentDate - TimeZone tz = TimeZone.getDefault(); - timeZone = calculateTimeZoneOffset(tz.getRawOffset()); - + timezone = TimeZone.getDefault(); + timeZoneNoDST = calculateTimeZoneOffset(timezone.getRawOffset()); + Calendar calendar = Calendar.getInstance(timezone); + int offset = calendar.get(Calendar.DST_OFFSET); + timeZoneDST = calculateTimeZoneOffset(timezone.getRawOffset()+offset); + if (fileDateFormat==null || fileDateFormat.length()==0) fileDateFormat = "yyyy-MM-dd"; dateFormatter = new SimpleDateFormat(fileDateFormat); - dateFormatter.setTimeZone(tz); + dateFormatter.setTimeZone(timezone); dayFormatter = new SimpleDateFormat("dd"); - dayFormatter.setTimeZone(tz); + dayFormatter.setTimeZone(timezone); monthFormatter = new SimpleDateFormat("MM"); - monthFormatter.setTimeZone(tz); + monthFormatter.setTimeZone(timezone); yearFormatter = new SimpleDateFormat("yyyy"); - yearFormatter.setTimeZone(tz); + yearFormatter.setTimeZone(timezone); timeFormatter = new SimpleDateFormat("HH:mm:ss"); - timeFormatter.setTimeZone(tz); + timeFormatter.setTimeZone(timezone); currentDateString = getCurrentDateString(); dateStamp = dateFormatter.format(new Date()); 1.273 +11 -0 jakarta-tomcat-catalina/webapps/docs/changelog.xml Index: changelog.xml =================================================================== RCS file: /home/cvs/jakarta-tomcat-catalina/webapps/docs/changelog.xml,v retrieving revision 1.272 retrieving revision 1.273 diff -u -r1.272 -r1.273 --- changelog.xml 26 Mar 2005 03:16:18 -0000 1.272 +++ changelog.xml 28 Mar 2005 19:06:38 -0000 1.273 @@ -26,6 +26,17 @@ </p> </section> +<section name="Tomcat 5.5.10 (yoavs)"> + <subsection name="Catalina"> + <changelog> + <fix> + <bug>20380</bug>: Access log timestamps now take account of Daylight Saving + Time (DST). (markt) + </fix> + </changelog> + </subsection> +</section> + <section name="Tomcat 5.5.9 (yoavs)"> <subsection name="General"> <changelog>
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]