From: kkolinko Date: Thu, 4 Aug 2011 03:53:27 +0000 (+0000) Subject: Split "condition" attribute of AccessLogValve into two, "conditionIf" and "conditionU... X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=6cb8861ab3c3f3e399b063ec7a2aeaa0aa5f8e03;p=tomcat7.0 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". git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1153742 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/catalina/valves/AccessLogValve.java b/java/org/apache/catalina/valves/AccessLogValve.java index c7570aa26..1490e34f0 100644 --- a/java/org/apache/catalina/valves/AccessLogValve.java +++ b/java/org/apache/catalina/valves/AccessLogValve.java @@ -135,9 +135,13 @@ import org.apache.tomcat.util.buf.B2CConverter; * *

* Conditional logging is also supported. This can be done with the - * condition property. - * If the value returned from ServletRequest.getAttribute(condition) + * conditionUnless and conditionIf 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 condition attribute is synonym for + * conditionUnless and is provided for backwards compatibility. *

* *

@@ -524,13 +528,19 @@ public class AccessLogValve extends ValveBase implements AccessLog { * 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 conditionUnless property. */ protected String condition = null; + /** + * Are we doing conditional logging. default null. + * It is the value of conditionIf 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 ValveBase implements AccessLog { /** + * 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 ValveBase implements AccessLog { @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; } diff --git a/java/org/apache/catalina/valves/mbeans-descriptors.xml b/java/org/apache/catalina/valves/mbeans-descriptors.xml index f5112ad30..7b0103bb4 100644 --- a/java/org/apache/catalina/valves/mbeans-descriptors.xml +++ b/java/org/apache/catalina/valves/mbeans-descriptors.xml @@ -44,6 +44,14 @@ writeable="false"/> + + + + @@ -204,6 +212,14 @@ writeable="false"/> + + + + diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index ac7e04335..5d1036f70 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -119,6 +119,12 @@ Make sure committed connection is returned to the pool if datasource is enabled. (kfujino) + + Split condition attribute of AccessLogValve into two, + conditionIf and conditionUnless. Implement + conditional logging that logs only if a request attribute is present. + (kkolinko) + diff --git a/webapps/docs/config/valve.xml b/webapps/docs/config/valve.xml index 6af03e693..327273387 100644 --- a/webapps/docs/config/valve.xml +++ b/webapps/docs/config/valve.xml @@ -168,7 +168,18 @@

- + +

Turns on conditional logging. If set, requests will be + logged only if ServletRequest.getAttribute() is + not null. For example, if this value is set to + important, then a particular request will only be logged + if ServletRequest.getAttribute("important") != null. + The use of Filters is an easy way to set/unset the attribute + in the ServletRequest on many different requests. +

+
+ +

Turns on conditional logging. If set, requests will be logged only if ServletRequest.getAttribute() is null. For example, if this value is set to @@ -179,6 +190,12 @@

+ +

The same as conditionUnless. This attribute is + provided for backwards compatibility. +

+
+

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 @@

- + +

Turns on conditional logging. If set, requests will be + logged only if ServletRequest.getAttribute() is + not null. For example, if this value is set to + important, then a particular request will only be logged + if ServletRequest.getAttribute("important") != null. + The use of Filters is an easy way to set/unset the attribute + in the ServletRequest on many different requests. +

+
+ +

Turns on conditional logging. If set, requests will be logged only if ServletRequest.getAttribute() is null. For example, if this value is set to @@ -371,6 +399,12 @@

+ +

The same as conditionUnless. This attribute is + provided for backwards compatibility. +

+
+

Allows a customized date format in the access log file name. The date format also decides how often the file is rotated.