Top Description Inners Fields Constructors Methods
org.apache.catalina.valves

public abstract Class AbstractAccessLogValve

extends ValveBase
implements AccessLog
Class Inheritance
All Implemented Interfaces
org.apache.catalina.AccessLog
Known Direct Subclasses
org.apache.catalina.valves.AccessLogValve
Imports
java.io.CharArrayWriter, .IOException, java.net.InetAddress, java.text.SimpleDateFormat, java.util.ArrayList, .Date, .Enumeration, .HashMap, .Iterator, .List, .Locale, .Map, .TimeZone, java.util.concurrent.TimeUnit, java.util.concurrent.atomic.AtomicBoolean, jakarta.servlet.RequestDispatcher, .ServletException, jakarta.servlet.http.Cookie, .HttpSession, org.apache.catalina.AccessLog, .Globals, .Session, org.apache.catalina.connector.ClientAbortException, .Request, .Response, org.apache.catalina.util.TLSUtil, org.apache.coyote.ActionCode, .RequestInfo, org.apache.juli.logging.Log, .LogFactory, org.apache.tomcat.util.ExceptionUtils, org.apache.tomcat.util.buf.HexUtils, org.apache.tomcat.util.collections.SynchronizedStack, org.apache.tomcat.util.net.IPv6Utils

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:

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

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:

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.

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

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static interface
AbstractAccessLogValve.AccessLogElement

AccessLogElement writes the partial message into the buffer.

protected static class
AbstractAccessLogValve.ByteSentElement

write bytes sent, excluding HTTP headers - %b, %B

protected static interface
AbstractAccessLogValve.CachedElement

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.ConnectionStatusElement

Write connection status when response is completed - %X

protected static class
AbstractAccessLogValve.CookieElement

write a specific cookie - %{xxx}c

protected class
AbstractAccessLogValve.DateAndTimeElement

write date and time, in configurable format (default CLF) - %t or %{format}t

protected static class
AbstractAccessLogValve.DateFormatCache

Cache structure for formatted timestamps based on seconds.

protected static class
AbstractAccessLogValve.ElapsedTimeElement

write time taken to process the request - %D, %T

protected static class
AbstractAccessLogValve.FirstByteTimeElement

write time until first byte is written (commit time) in millis - %F

private static enum
AbstractAccessLogValve.FormatType

The list of our time format types.

protected static class
AbstractAccessLogValve.HeaderElement

write incoming headers - %{xxx}i

protected class
AbstractAccessLogValve.HostElement

write remote host name - %h

protected static class
AbstractAccessLogValve.HttpStatusCodeElement

write HTTP status code of the response - %s

protected static class
AbstractAccessLogValve.LocalAddrElement

write local IP address - %A

protected class
protected static class
AbstractAccessLogValve.LogicalUserNameElement

write remote logical username from identd (always returns '-') - %l

protected static class
AbstractAccessLogValve.MethodElement

write request method (GET, POST, etc.) - %m

protected class
AbstractAccessLogValve.PortElement

write local or remote port for request connection - %p and %{xxx}p

private static enum
AbstractAccessLogValve.PortType

The list of our port types.

protected class
AbstractAccessLogValve.ProtocolElement

write request protocol - %H

protected static class
AbstractAccessLogValve.QueryElement

write Query string (prepended with a '?' if it exists) - %q

protected class
AbstractAccessLogValve.RemoteAddrElement

write remote IP address - %a

private static enum
AbstractAccessLogValve.RemoteAddressType

The list of our ip address types.

protected static class
AbstractAccessLogValve.RequestAttributeElement

write an attribute in the ServletRequest - %{xxx}r

protected static class
AbstractAccessLogValve.RequestElement

write first line of the request (method and request URI) - %r

protected static class
AbstractAccessLogValve.RequestURIElement

write requested URL path - %U

protected static class
AbstractAccessLogValve.ResponseHeaderElement

write a specific response header - %{xxx}o

protected static class
AbstractAccessLogValve.SessionAttributeElement

write an attribute in the HttpSession - %{xxx}s

protected static class
AbstractAccessLogValve.SessionIdElement

write user session ID - %S

protected static class
protected static class
protected static class
AbstractAccessLogValve.UserElement

write remote user that was authenticated (if any), else '-' - %u

Field Summary

Modifier and TypeField and Description
protected AbstractAccessLogValve.CachedElement[]
cachedElements

Array of elements where the value needs to be cached at the start of the request.

private SynchronizedStack<CharArrayWriter>
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.DateFormatCache
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<Date>
localDate

The system time when we last updated the Date that this valve uses for log lines.

private static final ThreadLocal<AbstractAccessLogValve.DateFormatCache>
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.AccessLogElement[]
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?

Inherited from org.apache.catalina.valves.ValveBase:
asyncSupportedcontainercontainerLognextsm

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected AbstractAccessLogValve.AccessLogElement

Returns:

the log element
createAccessLogElement
(String
Header name
name
,
char
char in the log pattern
pattern
)

Create an AccessLogElement implementation which needs an element name.

protected AbstractAccessLogValve.AccessLogElement

Returns:

the log element
createAccessLogElement
(char
char in the log pattern
pattern
)

Create an AccessLogElement implementation.

private AbstractAccessLogValve.CachedElement[]
protected AbstractAccessLogValve.AccessLogElement[]

Returns:

the log elements array
createLogElements
()

Parse pattern string and create the array of AccessLogElement.

protected static void
protected static Locale

Returns:

the locale object
findLocale
(String
The locale name
name
,
Locale
Fallback locale if the name is not found
fallback
)

Find a locale by name.

public String

Returns:

the attribute name
getCondition
()

Return whether the attribute name to look for when performing conditional logging.

public String

Returns:

the attribute name
getConditionIf
()

Return whether the attribute name to look for when performing conditional logging.

public String

Returns:

the attribute name
getConditionUnless
()

Return whether the attribute name to look for when performing conditional logging.

private static Date

Returns:

the date object
getDate
(long
The time
systime
)

This method returns a Date object that is accurate to within one second.

public boolean

Returns:

the enabled flag.
getEnabled
()

public boolean
public String

Returns:

the locale
getLocale
()

Return the locale used to format timestamps in log entries and in log file name suffix.

public int
public String

Returns:

the format pattern.
getPattern
()

public boolean
public void
invoke(Request
Request being processed
request
,
Response
Response being processed
response
)

Implements org.apache.catalina.Valve.invoke.

Log a message summarizing the specified request and response, according to the format specified by the pattern property.

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.apache.catalina.AccessLog.log.

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
setEnabled(boolean
The enabled to set.
enabled
)

public void
setIpv6Canonical(boolean ipv6Canonical)

public void
setLocale(String
The locale to use.
localeName
)

Set the locale used to format timestamps in log entries and in log file name suffix.

public void
setMaxLogMessageBufferSize(int maxLogMessageBufferSize)

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.
requestAttributesEnabled
)

Implements org.apache.catalina.AccessLog.setRequestAttributesEnabled.

Should this valve use request attributes for IP address, hostname, protocol and port used for the request?

Inherited from org.apache.catalina.valves.ValveBase:
backgroundProcessgetContainergetDomainInternalgetNextgetObjectNameKeyPropertiesinitInternalisAsyncSupportedsetAsyncSupportedsetContainersetNextstartInternalstopInternaltoString