You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2012/12/03 21:47:59 UTC

svn commit: r1416660 - in /tomcat/tc7.0.x/trunk: ./ java/org/apache/catalina/valves/AccessLogValve.java webapps/docs/changelog.xml

Author: markt
Date: Mon Dec  3 20:47:57 2012
New Revision: 1416660

URL: http://svn.apache.org/viewvc?rev=1416660&view=rev
Log:
Simplify the TimeZone handling in the AccessLogValve and correct a few edge cases.
The previous code did not handle edge cases - for example (and what ID'd this issue) the UK was at +01:00 from Oct 1968 to Oct 1971.
It is far better to let the formatted handle the TimeZone directly as it will handle all the edge cases.

Modified:
    tomcat/tc7.0.x/trunk/   (props changed)
    tomcat/tc7.0.x/trunk/java/org/apache/catalina/valves/AccessLogValve.java
    tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml

Propchange: tomcat/tc7.0.x/trunk/
------------------------------------------------------------------------------
  Merged /tomcat/trunk:r1416658

Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/valves/AccessLogValve.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/valves/AccessLogValve.java?rev=1416660&r1=1416659&r2=1416660&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/catalina/valves/AccessLogValve.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/valves/AccessLogValve.java Mon Dec  3 20:47:57 2012
@@ -246,25 +246,6 @@ public class AccessLogValve extends Valv
 
 
     /**
-     * The system timezone.
-     */
-    private static final TimeZone timezone;
-
-
-    /**
-     * The time zone offset relative to GMT in text form when daylight saving
-     * is not in operation.
-     */
-    private static final String timeZoneNoDST;
-
-
-    /**
-     * The time zone offset relative to GMT in text form when daylight saving
-     * is in operation.
-     */
-    private static final String timeZoneDST;
-
-    /**
      * The size of our global date format cache
      */
     private static final int globalCacheSize = 300;
@@ -312,7 +293,7 @@ public class AccessLogValve extends Valv
         protected class Cache {
 
             /* CLF log format */
-            private static final String cLFFormat = "dd/MMM/yyyy:HH:mm:ss";
+            private static final String cLFFormat = "dd/MMM/yyyy:HH:mm:ss Z";
 
             /* Second used to retrieve CLF format in most recent invocation */
             private long previousSeconds = Long.MIN_VALUE;
@@ -422,8 +403,6 @@ public class AccessLogValve extends Valv
                         StringBuilder current = new StringBuilder(32);
                         current.append('[');
                         current.append(previousFormat);
-                        current.append(' ');
-                        current.append(getTimeZone(currentDate));
                         current.append(']');
                         previousFormat = current.toString();
                     }
@@ -1221,40 +1200,6 @@ public class AccessLogValve extends Valv
     }
 
 
-    private static String getTimeZone(Date date) {
-        if (timezone.inDaylightTime(date)) {
-            return timeZoneDST;
-        } else {
-            return timeZoneNoDST;
-        }
-    }
-
-
-    private static String calculateTimeZoneOffset(long offset) {
-        StringBuilder tz = new StringBuilder();
-        if ((offset < 0)) {
-            tz.append("-");
-            offset = -offset;
-        } else {
-            tz.append("+");
-        }
-
-        long hourOffset = offset / (1000 * 60 * 60);
-        long minuteOffset = (offset / (1000 * 60)) % 60;
-
-        if (hourOffset < 10) {
-            tz.append("0");
-        }
-        tz.append(hourOffset);
-
-        if (minuteOffset < 10) {
-            tz.append("0");
-        }
-        tz.append(minuteOffset);
-
-        return tz.toString();
-    }
-
     /**
      * Find a locale by name
      */
@@ -1272,14 +1217,6 @@ public class AccessLogValve extends Valv
         return fallback;
     }
 
-    static {
-        // Initialize the timeZone
-        timezone = TimeZone.getDefault();
-        timeZoneNoDST = calculateTimeZoneOffset(timezone.getRawOffset());
-        int offset = timezone.getDSTSavings();
-        timeZoneDST = calculateTimeZoneOffset(timezone.getRawOffset() + offset);
-    }
-
 
     /**
      * Start this component and implement the requirements
@@ -1298,7 +1235,7 @@ public class AccessLogValve extends Valv
             setFileDateFormat(format);
         }
         fileDateFormatter = new SimpleDateFormat(format, Locale.US);
-        fileDateFormatter.setTimeZone(timezone);
+        fileDateFormatter.setTimeZone(TimeZone.getDefault());
         dateStamp = fileDateFormatter.format(new Date(System.currentTimeMillis()));
         if (rotatable && renameOnRotate) {
             restore();

Modified: tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml?rev=1416660&r1=1416659&r2=1416660&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Mon Dec  3 20:47:57 2012
@@ -82,6 +82,10 @@
         <bug>54220</bug>: Ensure the ErrorReportValve only generates an error
         report if the error flag on the response has been set. (markt)
       </fix>
+      <fix>
+        Simplify time zone handling in the access log valve and correctly handle
+        various edge cases for non-standard DST changes. (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Web applications">



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