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:46:09 UTC

svn commit: r1416658 - /tomcat/trunk/java/org/apache/catalina/valves/AccessLogValve.java

Author: markt
Date: Mon Dec  3 20:46:07 2012
New Revision: 1416658

URL: http://svn.apache.org/viewvc?rev=1416658&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/trunk/java/org/apache/catalina/valves/AccessLogValve.java

Modified: tomcat/trunk/java/org/apache/catalina/valves/AccessLogValve.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/valves/AccessLogValve.java?rev=1416658&r1=1416657&r2=1416658&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/valves/AccessLogValve.java (original)
+++ tomcat/trunk/java/org/apache/catalina/valves/AccessLogValve.java Mon Dec  3 20:46:07 2012
@@ -241,25 +241,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;
@@ -307,7 +288,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;
@@ -417,8 +398,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();
                     }
@@ -1223,40 +1202,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
      */
@@ -1274,14 +1219,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
@@ -1300,7 +1237,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();



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