Author: markt
Date: Thu Mar 14 15:47:24 2013
New Revision: 1456491

URL: http://svn.apache.org/r1456491
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=54660
Allow the AccessLogValve file data format to be changed via JMX. The change 
takes effect as soon as the next message is logged.

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=1456491&r1=1456490&r2=1456491&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/valves/AccessLogValve.java (original)
+++ tomcat/trunk/java/org/apache/catalina/valves/AccessLogValve.java Thu Mar 14 
15:47:24 2013
@@ -842,7 +842,18 @@ public class AccessLogValve extends Valv
      *  Set the date format date based log rotation.
      */
     public void setFileDateFormat(String fileDateFormat) {
-        this.fileDateFormat = fileDateFormat;
+        String newFormat;
+        if (fileDateFormat == null) {
+            newFormat = "";
+        } else {
+            newFormat = fileDateFormat;
+        }
+        this.fileDateFormat = newFormat;
+
+        synchronized (this) {
+            fileDateFormatter = new SimpleDateFormat(newFormat, Locale.US);
+            fileDateFormatter.setTimeZone(TimeZone.getDefault());
+        }
     }
 
 
@@ -961,6 +972,34 @@ public class AccessLogValve extends Valv
 
 
     /**
+     * Rotate the log file if necessary.
+     */
+    public void rotate() {
+        if (rotatable) {
+            // Only do a logfile switch check once a second, max.
+            long systime = System.currentTimeMillis();
+            if ((systime - rotationLastChecked) > 1000) {
+                synchronized(this) {
+                    if ((systime - rotationLastChecked) > 1000) {
+                        rotationLastChecked = systime;
+
+                        String tsDate;
+                        // Check for a change of date
+                        tsDate = fileDateFormatter.format(new Date(systime));
+
+                        // If the date has changed, switch log files
+                        if (!dateStamp.equals(tsDate)) {
+                            close(true);
+                            dateStamp = tsDate;
+                            open();
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    /**
      * Rename the existing log file to something else. Then open the
      * old log file name up once again. Intended to be called by a JMX
      * agent.
@@ -1091,28 +1130,8 @@ public class AccessLogValve extends Valv
      * @param message Message to be logged
      */
     public void log(CharArrayWriter message) {
-        if (rotatable) {
-            // Only do a logfile switch check once a second, max.
-            long systime = System.currentTimeMillis();
-            if ((systime - rotationLastChecked) > 1000) {
-                synchronized(this) {
-                    if ((systime - rotationLastChecked) > 1000) {
-                        rotationLastChecked = systime;
-
-                        String tsDate;
-                        // Check for a change of date
-                        tsDate = fileDateFormatter.format(new Date(systime));
 
-                        // If the date has changed, switch log files
-                        if (!dateStamp.equals(tsDate)) {
-                            close(true);
-                            dateStamp = tsDate;
-                            open();
-                        }
-                    }
-                }
-            }
-        }
+        rotate();
 
         /* In case something external rotated the file instead */
         if (checkExists) {
@@ -1232,10 +1251,6 @@ public class AccessLogValve extends Valv
 
         // Initialize the Date formatters
         String format = getFileDateFormat();
-        if (format == null) {
-            format = "";
-            setFileDateFormat(format);
-        }
         fileDateFormatter = new SimpleDateFormat(format, Locale.US);
         fileDateFormatter.setTimeZone(TimeZone.getDefault());
         dateStamp = fileDateFormatter.format(new 
Date(System.currentTimeMillis()));



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to