From: pero Date: Mon, 23 Apr 2007 14:17:49 +0000 (+0000) Subject: add enabled attribute to support JMX enable/disable logging. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=bba41da58475944bcef673ab4f8877c665ca6e0f;p=tomcat7.0 add enabled attribute to support JMX enable/disable logging. git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@531475 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/catalina/valves/AccessLogValve.java b/java/org/apache/catalina/valves/AccessLogValve.java index e4928131e..2e927fb02 100644 --- a/java/org/apache/catalina/valves/AccessLogValve.java +++ b/java/org/apache/catalina/valves/AccessLogValve.java @@ -158,6 +158,11 @@ public class AccessLogValve /** + * enabled this component + */ + protected boolean enabled = true; + + /** * The pattern used to format our access log lines. */ protected String pattern = null; @@ -312,6 +317,20 @@ public class AccessLogValve // ------------------------------------------------------------- Properties + /** + * @return Returns the enabled. + */ + public boolean getEnabled() { + return enabled; + } + + /** + * @param enabled + * The enabled to set. + */ + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } /** * Return the directory in which we create log files. @@ -519,7 +538,7 @@ public class AccessLogValve * throwables will be caught and logged. */ public void backgroundProcess() { - if (writer != null && buffered) { + if (started && getEnabled() && writer != null && buffered) { writer.flush(); } } @@ -537,27 +556,30 @@ public class AccessLogValve public void invoke(Request request, Response response) throws IOException, ServletException { - // Pass this request on to the next valve in our pipeline - long t1 = System.currentTimeMillis(); - - getNext().invoke(request, response); - - long t2 = System.currentTimeMillis(); - long time = t2 - t1; - - if (logElements == null || condition != null - && null != request.getRequest().getAttribute(condition)) { - return; - } - - Date date = getDate(); - StringBuffer result = new StringBuffer(); - - for (int i = 0; i < logElements.length; i++) { - logElements[i].addElement(result, date, request, response, time); - } - - log(result.toString()); + if (started && getEnabled()) { + // Pass this request on to the next valve in our pipeline + long t1 = System.currentTimeMillis(); + + getNext().invoke(request, response); + + long t2 = System.currentTimeMillis(); + long time = t2 - t1; + + if (logElements == null || condition != null + && null != request.getRequest().getAttribute(condition)) { + return; + } + + Date date = getDate(); + StringBuffer result = new StringBuffer(); + + for (int i = 0; i < logElements.length; i++) { + logElements[i].addElement(result, date, request, response, time); + } + + log(result.toString()); + } else + getNext().invoke(request, response); } diff --git a/java/org/apache/catalina/valves/mbeans-descriptors.xml b/java/org/apache/catalina/valves/mbeans-descriptors.xml index 1a9667b8c..0b0836696 100644 --- a/java/org/apache/catalina/valves/mbeans-descriptors.xml +++ b/java/org/apache/catalina/valves/mbeans-descriptors.xml @@ -17,6 +17,11 @@ type="java.lang.String" writeable="false"/> + + @@ -109,6 +114,11 @@ type="java.lang.String" writeable="false"/> + + @@ -174,6 +184,11 @@ type="java.lang.String" writeable="false"/> + + diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index c850e00b9..e8020c2a6 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -28,6 +28,9 @@ 41655 Fix message translations. Japanese translations provided by Suzuki Yuichiro. (markt) + + Add enabled attribute to AccessLogValve (pero) +