Class AbstractAccessLogValve

java.lang.Object
All Implemented Interfaces:
MBeanRegistration, AccessLog, Contained, JmxEnabled, Lifecycle, Valve
Direct Known Subclasses:
AccessLogValve

public abstract class AbstractAccessLogValve extends ValveBase implements AccessLog

Abstract implementation of the Valve interface that generates a web server access log with the detailed line contents matching a configurable pattern. The syntax of the available patterns is similar to that supported by the Apache HTTP Server mod_log_config module.

Patterns for the logged message may include constant text or any of the following replacement strings, for which the corresponding information from the specified Response is substituted:

  • %a - Remote IP address
  • %A - Local IP address
  • %b - Bytes sent, excluding HTTP headers, or '-' if no bytes were sent
  • %B - Bytes sent, excluding HTTP headers
  • %h - Remote host name (or IP address if enableLookups for the connector is false)
  • %H - Request protocol
  • %l - Remote logical username from identd (always returns '-')
  • %m - Request method
  • %p - Local port
  • %q - Query string (prepended with a '?' if it exists, otherwise an empty string
  • %r - First line of the request
  • %s - HTTP status code of the response
  • %S - User session ID
  • %t - Date and time, in Common Log Format format
  • %u - Remote user that was authenticated
  • %U - Requested URL path
  • %v - Local server name
  • %D - Time taken to process the request, in microseconds
  • %T - Time taken to process the request, in seconds
  • %F - Time taken to commit the response, in milliseconds
  • %I - current Request thread name (can compare later with stacktraces)
  • %X - Connection status when response is completed:
    • X = Connection aborted before the response completed.
    • + = Connection may be kept alive after the response is sent.
    • - = Connection will be closed after the response is sent.

In addition, the caller can specify one of the following aliases for commonly utilized patterns:

  • common - %h %l %u %t "%r" %s %b
  • combined - %h %l %u %t "%r" %s %b "%{Referer}i" "%{User-Agent}i"

There is also support to write information from the cookie, incoming header, the Session or something else in the ServletRequest.
It is modeled after the Apache HTTP Server log configuration syntax:

  • %{xxx}i for incoming headers
  • %{xxx}o for outgoing response headers
  • %{xxx}c for a specific cookie
  • %{xxx}r xxx is an attribute in the ServletRequest
  • %{xxx}s xxx is an attribute in the HttpSession
  • %{xxx}t xxx is an enhanced SimpleDateFormat pattern (see Configuration Reference document for details on supported time patterns)
  • %{xxx}T xxx is the unit for the time taken to process the request (see Configuration Reference document for details on supported units)

Conditional logging is also supported. This can be done with the 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.

For extended attributes coming from a getAttribute() call, it is you responsibility to ensure there are no newline or control characters.

Author:
Craig R. McClanahan, Jason Brittain, Remy Maucherat, Takayuki Kaneko, Peter Rossbach