*
* <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>
* 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!
/**
+ * 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() {
@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;
}
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"/>
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"/>
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">
</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
</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.
</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
</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.