tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kkoli...@apache.org
Subject svn commit: r1153742 - in /tomcat/trunk: java/org/apache/catalina/valves/AccessLogValve.java java/org/apache/catalina/valves/mbeans-descriptors.xml webapps/docs/changelog.xml webapps/docs/config/valve.xml
Date Thu, 04 Aug 2011 03:53:28 GMT
Author: kkolinko
Date: Thu Aug  4 03:53:27 2011
New Revision: 1153742

URL: http://svn.apache.org/viewvc?rev=1153742&view=rev
Log:
Split "condition" attribute of AccessLogValve into two, "conditionIf" and "conditionUnless".
Implement conditional logging that logs only if a request attribute is present.
The old attribute "condition" is provided as well, for backwards compatibility, and is equal
to "conditionUnless".

Modified:
    tomcat/trunk/java/org/apache/catalina/valves/AccessLogValve.java
    tomcat/trunk/java/org/apache/catalina/valves/mbeans-descriptors.xml
    tomcat/trunk/webapps/docs/changelog.xml
    tomcat/trunk/webapps/docs/config/valve.xml

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=1153742&r1=1153741&r2=1153742&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/valves/AccessLogValve.java (original)
+++ tomcat/trunk/java/org/apache/catalina/valves/AccessLogValve.java Thu Aug  4 03:53:27 2011
@@ -135,9 +135,13 @@ import org.apache.tomcat.util.buf.B2CCon
  * 
  * <p>
  * Conditional logging is also supported. This can be done with the
- * <code>condition</code> property.
- * If the value returned from ServletRequest.getAttribute(condition)
+ * <code>conditionUnless</code> and <code>conditionIf</code> properties.
+ * If the value returned from ServletRequest.getAttribute(conditionUnless)
  * yields a non-null value, the logging will be skipped.
+ * If the value returned from ServletRequest.getAttribute(conditionIf)
+ * yields the null value, the logging will be skipped.
+ * The <code>condition</code> attribute is synonym for
+ * <code>conditionUnless</code> and is provided for backwards compatibility.
  * </p>
  * 
  * <p>
@@ -524,13 +528,19 @@ public class AccessLogValve extends Valv
      * agent renames the log file so we can automagically recreate it.
      */
     private boolean checkExists = false;
-    
-    
+
+
     /**
-     * Are we doing conditional logging. default false.
+     * Are we doing conditional logging. default null.
+     * It is the value of <code>conditionUnless</code> property.
      */
     protected String condition = null;
 
+    /**
+     * Are we doing conditional logging. default null.
+     * It is the value of <code>conditionIf</code> property.
+     */
+    protected String conditionIf = null;
 
     /**
      * Date format to place in log file name. Use at your own risk!
@@ -788,6 +798,46 @@ public class AccessLogValve extends Valv
 
 
     /**
+     * Return whether the attribute name to look for when
+     * performing conditional logging. If null, every
+     * request is logged.
+     */
+    public String getConditionUnless() {
+        return getCondition();
+    }
+
+
+    /**
+     * Set the ServletRequest.attribute to look for to perform
+     * conditional logging. Set to null to log everything.
+     *
+     * @param condition Set to null to log everything
+     */
+    public void setConditionUnless(String condition) {
+        setCondition(condition);
+    }
+
+    /**
+     * Return whether the attribute name to look for when
+     * performing conditional logging. If null, every
+     * request is logged.
+     */
+    public String getConditionIf() {
+        return conditionIf;
+    }
+
+
+    /**
+     * Set the ServletRequest.attribute to look for to perform
+     * conditional logging. Set to null to log everything.
+     *
+     * @param condition Set to null to log everything
+     */
+    public void setConditionIf(String condition) {
+        this.conditionIf = condition;
+    }
+
+    /**
      *  Return the date format date based log rotation.
      */
     public String getFileDateFormat() {
@@ -882,9 +932,11 @@ public class AccessLogValve extends Valv
     
     @Override
     public void log(Request request, Response response, long time) {
-        if (!getState().isAvailable() || !getEnabled() ||
-                logElements == null || condition != null
-                && null != request.getRequest().getAttribute(condition)) {
+        if (!getState().isAvailable() || !getEnabled() || logElements == null
+                || condition != null
+                && null != request.getRequest().getAttribute(condition)
+                || conditionIf != null
+                && null == request.getRequest().getAttribute(conditionIf)) {
             return;
         }
 

Modified: tomcat/trunk/java/org/apache/catalina/valves/mbeans-descriptors.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/valves/mbeans-descriptors.xml?rev=1153742&r1=1153741&r2=1153742&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/valves/mbeans-descriptors.xml (original)
+++ tomcat/trunk/java/org/apache/catalina/valves/mbeans-descriptors.xml Thu Aug  4 03:53:27
2011
@@ -44,6 +44,14 @@
                writeable="false"/>
 
     <attribute name="condition"
+               description="The value to look for conditional logging. The same as conditionUnless."
+               type="java.lang.String"/>
+
+    <attribute name="conditionIf"
+               description="The value to look for conditional logging."
+               type="java.lang.String"/>
+
+    <attribute name="conditionUnless"
                description="The value to look for conditional logging."
                type="java.lang.String"/>
 
@@ -204,6 +212,14 @@
                writeable="false"/>
 
     <attribute name="condition"
+               description="The value to look for conditional logging. The same as conditionUnless."
+               type="java.lang.String"/>
+
+    <attribute name="conditionIf"
+               description="The value to look for conditional logging."
+               type="java.lang.String"/>
+
+    <attribute name="conditionUnless"
                description="The value to look for conditional logging."
                type="java.lang.String"/>
 

Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1153742&r1=1153741&r2=1153742&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Thu Aug  4 03:53:27 2011
@@ -119,6 +119,12 @@
         Make sure committed connection is returned to the pool if datasource is 
         enabled. (kfujino)
       </fix>
+      <add>
+        Split <code>condition</code> attribute of AccessLogValve into two,
+        <code>conditionIf</code> and <code>conditionUnless</code>.
Implement
+        conditional logging that logs only if a request attribute is present.
+        (kkolinko)
+      </add>
     </changelog>
   </subsection>
   <subsection name="Coyote">

Modified: tomcat/trunk/webapps/docs/config/valve.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/config/valve.xml?rev=1153742&r1=1153741&r2=1153742&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/config/valve.xml (original)
+++ tomcat/trunk/webapps/docs/config/valve.xml Thu Aug  4 03:53:27 2011
@@ -168,7 +168,18 @@
         </p>
       </attribute>
 
-      <attribute name="condition" required="false">
+      <attribute name="conditionIf" required="false">
+        <p>Turns on conditional logging. If set, requests will be
+           logged only if <code>ServletRequest.getAttribute()</code> is
+           not null. For example, if this value is set to
+           <code>important</code>, then a particular request will only be logged
+           if <code>ServletRequest.getAttribute("important") != null</code>.
+           The use of Filters is an easy way to set/unset the attribute
+           in the ServletRequest on many different requests.
+        </p>
+      </attribute>
+
+      <attribute name="conditionUnless" required="false">
         <p>Turns on conditional logging. If set, requests will be
            logged only if <code>ServletRequest.getAttribute()</code> is
            null. For example, if this value is set to
@@ -179,6 +190,12 @@
         </p>
       </attribute>
 
+      <attribute name="condition" required="false">
+        <p>The same as <code>conditionUnless</code>. This attribute is
+           provided for backwards compatibility.
+        </p>
+      </attribute>
+
       <attribute name="fileDateFormat" required="false">
         <p>Allows a customized date format in the access log file name.
            The date format also decides how often the file is rotated.
@@ -360,7 +377,18 @@
         </p>
       </attribute>
 
-      <attribute name="condition" required="false">
+      <attribute name="conditionIf" required="false">
+        <p>Turns on conditional logging. If set, requests will be
+           logged only if <code>ServletRequest.getAttribute()</code> is
+           not null. For example, if this value is set to
+           <code>important</code>, then a particular request will only be logged
+           if <code>ServletRequest.getAttribute("important") != null</code>.
+           The use of Filters is an easy way to set/unset the attribute
+           in the ServletRequest on many different requests.
+        </p>
+      </attribute>
+
+      <attribute name="conditionUnless" required="false">
         <p>Turns on conditional logging. If set, requests will be
            logged only if <code>ServletRequest.getAttribute()</code> is
            null. For example, if this value is set to
@@ -371,6 +399,12 @@
         </p>
       </attribute>
 
+      <attribute name="condition" required="false">
+        <p>The same as <code>conditionUnless</code>. This attribute is
+           provided for backwards compatibility.
+        </p>
+      </attribute>
+
       <attribute name="fileDateFormat" required="false">
         <p>Allows a customized date format in the access log file name.
            The date format also decides how often the file is rotated.



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


Mime
View raw message