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:
%h %l %u %t "%r" %s %b
%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.
| Modifier and Type | Class and Description |
|---|---|
| protected static interface | AbstractAccessLogValve.
AccessLogElement writes the partial message into the buffer. |
| protected static class | AbstractAccessLogValve.
write bytes sent, excluding HTTP headers - %b, %B |
| protected static interface | AbstractAccessLogValve.
Marks an AccessLogElement as needing to be have the value cached at the start of the request rather than just recorded at the end as the source data for the element may not be available at the end of the request. |
| protected static class | AbstractAccessLogValve.
Write connection status when response is completed - %X |
| protected static class | AbstractAccessLogValve.
write a specific cookie - %{xxx}c |
| protected class | AbstractAccessLogValve.
write date and time, in configurable format (default CLF) - %t or %{format}t |
| protected static class | AbstractAccessLogValve.
Cache structure for formatted timestamps based on seconds. |
| protected static class | AbstractAccessLogValve.
write time taken to process the request - %D, %T |
| protected static class | AbstractAccessLogValve.
write time until first byte is written (commit time) in millis - %F |
| private static enum | AbstractAccessLogValve.
The list of our time format types. |
| protected static class | AbstractAccessLogValve.
write incoming headers - %{xxx}i |
| protected class | AbstractAccessLogValve.
write remote host name - %h |
| protected static class | AbstractAccessLogValve.
write HTTP status code of the response - %s |
| protected static class | AbstractAccessLogValve.
write local IP address - %A |
| protected class | AbstractAccessLogValve.
write local server name - %v |
| protected static class | AbstractAccessLogValve.
write remote logical username from identd (always returns '-') - %l |
| protected static class | AbstractAccessLogValve.
write request method (GET, POST, etc.) - %m |
| protected class | AbstractAccessLogValve.
write local or remote port for request connection - %p and %{xxx}p |
| private static enum | AbstractAccessLogValve.
The list of our port types. |
| protected class | AbstractAccessLogValve.
write request protocol - %H |
| protected static class | AbstractAccessLogValve.
write Query string (prepended with a '?' if it exists) - %q |
| protected class | AbstractAccessLogValve.
write remote IP address - %a |
| private static enum | AbstractAccessLogValve.
The list of our ip address types. |
| protected static class | AbstractAccessLogValve.
write an attribute in the ServletRequest - %{xxx}r |
| protected static class | AbstractAccessLogValve.
write first line of the request (method and request URI) - %r |
| protected static class | AbstractAccessLogValve.
write requested URL path - %U |
| protected static class | AbstractAccessLogValve.
write a specific response header - %{xxx}o |
| protected static class | AbstractAccessLogValve.
write an attribute in the HttpSession - %{xxx}s |
| protected static class | AbstractAccessLogValve.
write user session ID - %S |
| protected static class | AbstractAccessLogValve.
write any string |
| protected static class | AbstractAccessLogValve.
write thread name - %I |
| protected static class | AbstractAccessLogValve.
write remote user that was authenticated (if any), else '-' - %u |
| Modifier and Type | Field and Description |
|---|---|
| protected AbstractAccessLogValve. | cachedElements
Array of elements where the value needs to be cached at the start of the request. |
| private SynchronizedStack | charArrayWriters
Buffer pool used for log message generation. |
| protected String | condition
Are we doing conditional logging. |
| protected String | conditionIf
Are we doing conditional logging. |
| protected boolean | enabled
enabled this component |
| private static final int | globalCacheSize
The size of our global date format cache |
| private static final AbstractAccessLogValve. | globalDateCache
Global date format cache. |
| private boolean | ipv6Canonical
Use IPv6 canonical representation format as defined by RFC 5952. |
| private static final int | localCacheSize
The size of our thread local date format cache |
| private static final ThreadLocal | localDate
The system time when we last updated the Date that this valve uses for log lines. |
| private static final ThreadLocal | localDateCache
Thread local date format cache. |
| protected Locale | locale
Locale used to format timestamps in log entries and in log file name suffix. |
| protected String | localeName
Name of locale used to format timestamps in log entries and in log file name suffix. |
| private static final Log | |
| protected AbstractAccessLogValve. | logElements
Array of AccessLogElement, they will be used to make log message. |
| private int | maxLogMessageBufferSize
Log message buffers are usually recycled and re-used. |
| protected String | pattern
The pattern used to format our access log lines. |
| protected boolean | requestAttributesEnabled
Should this valve use request attributes for IP address, hostname, protocol and port used for the request. |
| private boolean | tlsAttributeRequired
Does the configured log pattern include a known TLS attribute? |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| protected AbstractAccessLogValve. | Returns: the log elementHeader name name, char char in the log pattern pattern)Create an AccessLogElement implementation which needs an element name. |
| protected AbstractAccessLogValve. | Returns: the log elementchar in the log pattern pattern)Create an AccessLogElement implementation. |
| private AbstractAccessLogValve. | |
| protected AbstractAccessLogValve. | Returns: the log elements arrayParse pattern string and create the array of AccessLogElement. |
| protected static void | |
| protected static Locale | Returns: the locale objectThe locale name name, Locale Fallback locale if the name is not found fallback)Find a locale by name. |
| public String | Returns: the attribute nameReturn whether the attribute name to look for when performing conditional logging. |
| public String | Returns: the attribute nameReturn whether the attribute name to look for when performing conditional logging. |
| public String | Returns: the attribute nameReturn whether the attribute name to look for when performing conditional logging. |
| private static Date | Returns: the date objectThe time systime)This method returns a Date object that is accurate to within one second. |
| public boolean | |
| public boolean | |
| public String | Returns: the localeReturn the locale used to format timestamps in log entries and in log file name suffix. |
| public int | |
| public String | |
| public boolean | |
| public void | invoke(Request
Request being processed request, Response Response being processed response)Implements org. Log a message summarizing the specified request and response, according to the format specified by the
|
| public void | log(Request
Request (associated with the response) to log request, Response Response (associated with the request) to log response, long Time taken to process the request/response in
nanoseconds (use 0 if not known); in Tomcat
versions prior to 10, the time unit was
milliseconds time)Implements org. Add the request/response to the access log using the specified processing time. |
| protected abstract void | log(CharArrayWriter
Message to be logged. This object will be recycled by the calling method. message)Log the specified message. |
| public void | setCondition(String
Set to null to log everything condition)Set the ServletRequest.attribute to look for to perform conditional logging. |
| public void | setConditionIf(String
Set to null to log everything condition)Set the ServletRequest.attribute to look for to perform conditional logging. |
| public void | setConditionUnless(String
Set to null to log everything condition)Set the ServletRequest.attribute to look for to perform conditional logging. |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | setPattern(String
The new pattern pattern)Set the format pattern, first translating any recognized alias. |
| public void | setRequestAttributesEnabled(boolean
true causes the attributes
to be used, false causes
the original values to be used.Implements org. Should this valve use request attributes for IP address, hostname, protocol and port used for the request? |