add enabled attribute to support JMX enable/disable logging.
authorpero <pero@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 23 Apr 2007 14:17:49 +0000 (14:17 +0000)
committerpero <pero@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 23 Apr 2007 14:17:49 +0000 (14:17 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@531475 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/valves/AccessLogValve.java
java/org/apache/catalina/valves/mbeans-descriptors.xml
webapps/docs/changelog.xml

index e492813..2e927fb 100644 (file)
@@ -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);       
     }
 
     
index 1a9667b..0b08366 100644 (file)
                type="java.lang.String"
                writeable="false"/>
 
+     <attribute name="enabled"
+               description="Enable Access Logging"
+               is="true"
+               type="boolean"/>
+
     <attribute name="containerName"
                description="Object name of the container"
                type="javax.management.ObjectName"/>
                type="java.lang.String"
                writeable="false"/>
 
+     <attribute name="enabled"
+               description="Enable Access Logging"
+               is="true"
+               type="boolean"/>
     <attribute name="containerName"
                description="Object name of the container"
                type="javax.management.ObjectName"/>
                type="java.lang.String"
                writeable="false"/>
 
+    <attribute name="enabled"
+               description="Enable Access Logging"
+               is="true"
+               type="boolean"/>
+
     <attribute name="containerName"
                description="Object name of the container"
                type="javax.management.ObjectName"/>
index c850e00..e8020c2 100644 (file)
@@ -28,6 +28,9 @@
         <bug>41655</bug> Fix message translations. Japanese translations
         provided by Suzuki Yuichiro. (markt)
       </fix>
+      <add>
+        Add enabled attribute to AccessLogValve (pero)
+      </add>      
     </changelog>
   </subsection>
   <subsection name="Coyote">