Author: markt Date: Thu Mar 14 15:55:43 2013 New Revision: 1456499 URL: http://svn.apache.org/r1456499 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/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:r1456491,1456494 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=1456499&r1=1456498&r2=1456499&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 Thu Mar 14 15:55:43 2013 @@ -856,7 +856,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()); + } } @@ -967,6 +978,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. @@ -1097,28 +1136,8 @@ public class AccessLogValve extends Valv * @param message Message to be logged */ public void log(String 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) { @@ -1230,10 +1249,6 @@ public class AccessLogValve extends Valv // Initialize the Date formatters String format = getFileDateFormat(); - if (format == null || format.length() == 0) { - format = "yyyy-MM-dd"; - setFileDateFormat(format); - } fileDateFormatter = new SimpleDateFormat(format, Locale.US); fileDateFormatter.setTimeZone(TimeZone.getDefault()); dateStamp = fileDateFormatter.format(new Date(System.currentTimeMillis())); 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=1456499&r1=1456498&r2=1456499&view=diff ============================================================================== --- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original) +++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Thu Mar 14 15:55:43 2013 @@ -70,6 +70,12 @@ Ensure that, if a call to UEncoder#encodeURL is made, all internal structures are properly cleaned. (violetagg) </fix> + <add> + <bug>54660</bug>: Enable the modification of an access log's + <code>fileDateFormat</code> attribute while the access log is in use. + The change will take effect when the next entry is made to the access + log. (markt) + </add> </changelog> </subsection> <subsection name="Coyote"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org