Class AbstractAccessLogValve
- All Implemented Interfaces:
MBeanRegistration, AccessLog, Contained, JmxEnabled, Lifecycle, Valve
- Direct Known Subclasses:
AccessLogValve
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 ifenableLookupsfor 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}ifor incoming headers%{xxx}ofor outgoing response headers%{xxx}cfor a specific cookie%{xxx}rxxx is an attribute in the ServletRequest%{xxx}sxxx is an attribute in the HttpSession%{xxx}txxx is an enhanced SimpleDateFormat pattern (see Configuration Reference document for details on supported time patterns)%{xxx}Lxxx is the identifier to log (see Configuration Reference document for details on supported identifiers)%{xxx}Txxx 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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static interfaceAccessLogElement writes the partial message into the buffer.protected static classWrite bytes sent, excluding HTTP headers - %b, %B.protected static interfaceMarks an AccessLogElement as needing to 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 classWrite connection status when response is completed - %X.protected static classWrite a specific cookie - %{xxx}c.protected classWrite date and time, in configurable format (default CLF) - %t or %{format}t.protected static classCache structure for formatted timestamps based on seconds.protected static classWrite time taken to process the request - %D, %T.protected static classWrite time until first byte is written (commit time) in millis - %F.protected static classWrite incoming headers - %{xxx}i.protected classWrite remote host name - %h.protected static classWrite HTTP status code of the response - %s.protected static classWrite identifier element %{xxx}L.protected static classWrite local IP address - %A.protected classWrite local server name - %v.protected static classWrite remote logical username from identd (always returns '-') - %l.protected static classWrite request method (GET, POST, etc.) - %m.protected classWrite local or remote port for request connection - %p and %{xxx}p.protected classWrite request protocol - %H.protected static classWrite query string (prepended with a '?'protected classWrite remote IP address - %a.protected static classWrite an attribute in the ServletRequest - %{xxx}r.protected static classWrite first line of the request (method and request URI) - %r.protected static classWrite requested URL path - %U.protected static classWrite a specific response header - %{xxx}o.protected static classWrite an attribute in the HttpSession - %{xxx}s.protected static classWrite user session ID - %S.protected static classWrite any constant string.protected static classWrite thread name - %I.protected static classWrite remote user that was authenticated (if any), else '-' - %u.Nested classes/interfaces inherited from interface Lifecycle
Lifecycle.SingleUse -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected AbstractAccessLogValve.CachedElement[]Array of elements where the value needs to be cached at the start of the request.protected StringAre we doing conditional logging ?protected StringAre we doing conditional logging ?protected booleanenabled this componentprotected LocaleLocale used to format timestamps in log entries and in log file name suffix.protected StringName of locale used to format timestamps in log entries and in log file name suffix.protected AbstractAccessLogValve.AccessLogElement[]Array of AccessLogElement, they will be used to make log message.protected StringThe pattern used to format our access log lines.protected booleanShould this valve use request attributes for IP address, hostname, protocol and port used for the request.Fields inherited from class ValveBase
asyncSupported, container, containerLog, next, smFields inherited from interface AccessLog
PROTOCOL_ATTRIBUTE, REMOTE_ADDR_ATTRIBUTE, REMOTE_HOST_ATTRIBUTE, SERVER_NAME_ATTRIBUTE, SERVER_PORT_ATTRIBUTEFields inherited from interface Lifecycle
AFTER_DESTROY_EVENT, AFTER_INIT_EVENT, AFTER_START_EVENT, AFTER_STOP_EVENT, BEFORE_DESTROY_EVENT, BEFORE_INIT_EVENT, BEFORE_START_EVENT, BEFORE_STOP_EVENT, CONFIGURE_START_EVENT, CONFIGURE_STOP_EVENT, PERIODIC_EVENT, START_EVENT, STOP_EVENT -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected static voidappendQueryString(String query, CharArrayWriter buf, boolean appendDelim, boolean escapeQuoteAsDouble, boolean writeDashOnNull) protected AbstractAccessLogValve.AccessLogElementcreateAccessLogElement(char pattern) Create an AccessLogElement implementation.protected AbstractAccessLogValve.AccessLogElementcreateAccessLogElement(String name, char pattern) Create an AccessLogElement implementation which needs an element name.protected AbstractAccessLogValve.AccessLogElement[]Parse pattern string and create the array of AccessLogElement.protected static voidescapeAndAppend(String input, CharArrayWriter dest) Escapes and appends the input string to the destination writer.protected static voidescapeAndAppend(String input, CharArrayWriter dest, boolean escapeQuoteAsDouble) Escapes and appends the input string to the destination writer.protected static LocalefindLocale(String name, Locale fallback) Find a locale by name.Return whether the attribute name to look for when performing conditional logging.Return whether the attribute name to look for when performing conditional logging.Return whether the attribute name to look for when performing conditional logging.booleanReturns the enabled flag.booleanReturns the ipv6 canonical flag.Return the locale used to format timestamps in log entries and in log file name suffix.intReturns the max log message buffer size.Returns the format pattern.booleanChecks if request attributes will be logged.voidPerform request processing as required by this Valve.protected abstract voidlog(CharArrayWriter message) Log the specified message.voidAdd the request/response to the access log using the specified processing time.voidsetCondition(String condition) Set the ServletRequest.attribute to look for to perform conditional logging.voidsetConditionIf(String condition) Set the ServletRequest.attribute to look for to perform conditional logging.voidsetConditionUnless(String condition) Set the ServletRequest.attribute to look for to perform conditional logging.voidsetEnabled(boolean enabled) Sets the enabled flag.voidsetIpv6Canonical(boolean ipv6Canonical) Sets the ipv6 canonical flag.voidSet the locale used to format timestamps in log entries and in log file name suffix.voidsetMaxLogMessageBufferSize(int maxLogMessageBufferSize) Sets the max log message buffer size.voidsetPattern(String pattern) Set the format pattern, first translating any recognized alias.voidsetRequestAttributesEnabled(boolean requestAttributesEnabled) Should this valve use request attributes for IP address, hostname, protocol and port used for the request?Methods inherited from class ValveBase
backgroundProcess, getContainer, getDomainInternal, getNext, getObjectNameKeyProperties, initInternal, isAsyncSupported, setAsyncSupported, setContainer, setNext, startInternal, stopInternal, toStringMethods inherited from class LifecycleMBeanBase
destroyInternal, getDomain, getObjectName, postDeregister, postRegister, preDeregister, preRegister, register, setDomain, unregister, unregisterMethods inherited from class LifecycleBase
addLifecycleListener, destroy, findLifecycleListeners, fireLifecycleEvent, getState, getStateName, getThrowOnFailure, init, removeLifecycleListener, setState, setState, setThrowOnFailure, start, stop
-
Field Details
-
enabled
protected boolean enabledenabled this component -
pattern
The pattern used to format our access log lines. -
condition
Are we doing conditional logging ? default null. It is the value ofconditionUnlessproperty. -
conditionIf
Are we doing conditional logging ? default null. It is the value ofconditionIfproperty. If the ServletRequest.getAttribute(conditionIf) yields a non-null value, the logging will be performed. -
localeName
Name of locale used to format timestamps in log entries and in log file name suffix. -
locale
Locale used to format timestamps in log entries and in log file name suffix. -
logElements
Array of AccessLogElement, they will be used to make log message. -
cachedElements
Array of elements where the value needs to be cached at the start of the request. -
requestAttributesEnabled
protected boolean requestAttributesEnabledShould this valve use request attributes for IP address, hostname, protocol and port used for the request. Default isfalse.- See Also:
-
-
Constructor Details
-
AbstractAccessLogValve
public AbstractAccessLogValve()Default constructor.
-
-
Method Details
-
getMaxLogMessageBufferSize
public int getMaxLogMessageBufferSize()Returns the max log message buffer size.- Returns:
- the max log message buffer size.
-
setMaxLogMessageBufferSize
public void setMaxLogMessageBufferSize(int maxLogMessageBufferSize) Sets the max log message buffer size.- Parameters:
maxLogMessageBufferSize- The max log message buffer size.
-
getIpv6Canonical
public boolean getIpv6Canonical()Returns the ipv6 canonical flag.- Returns:
- the ipv6 canonical flag.
-
setIpv6Canonical
public void setIpv6Canonical(boolean ipv6Canonical) Sets the ipv6 canonical flag.- Parameters:
ipv6Canonical- The ipv6 canonical flag.
-
setRequestAttributesEnabled
public void setRequestAttributesEnabled(boolean requestAttributesEnabled) Should this valve use request attributes for IP address, hostname, protocol and port used for the request? The attributes used are:- org.apache.catalina.RemoteAddr
- org.apache.catalina.RemoteHost
- org.apache.catalina.Protocol
- org.apache.catalina.ServerName
- org.apache.catalina.ServerPost
false.- Specified by:
setRequestAttributesEnabledin interfaceAccessLog- Parameters:
requestAttributesEnabled-truecauses the attributes to be used,falsecauses the original values to be used.
-
getRequestAttributesEnabled
public boolean getRequestAttributesEnabled()Description copied from interface:AccessLogChecks if request attributes will be logged.- Specified by:
getRequestAttributesEnabledin interfaceAccessLog- Returns:
trueif the attributes will be logged, otherwisefalse- See Also:
-
getEnabled
public boolean getEnabled()Returns the enabled flag.- Returns:
- the enabled flag.
-
setEnabled
public void setEnabled(boolean enabled) Sets the enabled flag.- Parameters:
enabled- The enabled to set.
-
getPattern
-
setPattern
Set the format pattern, first translating any recognized alias.- Parameters:
pattern- The new pattern
-
getCondition
Return whether the attribute name to look for when performing conditional logging. If null, every request is logged.- Returns:
- the attribute name
-
setCondition
Set the ServletRequest.attribute to look for to perform conditional logging. Set to null to log everything.- Parameters:
condition- Set to null to log everything
-
getConditionUnless
Return whether the attribute name to look for when performing conditional logging. If null, every request is logged.- Returns:
- the attribute name
-
setConditionUnless
Set the ServletRequest.attribute to look for to perform conditional logging. Set to null to log everything.- Parameters:
condition- Set to null to log everything
-
getConditionIf
Return whether the attribute name to look for when performing conditional logging. If null, every request is logged.- Returns:
- the attribute name
-
setConditionIf
Set the ServletRequest.attribute to look for to perform conditional logging. Set to null to log everything.- Parameters:
condition- Set to null to log everything
-
getLocale
Return the locale used to format timestamps in log entries and in log file name suffix.- Returns:
- the locale
-
setLocale
Set the locale used to format timestamps in log entries and in log file name suffix. Changing the locale is only supported as long as the AccessLogValve has not logged anything. Changing the locale later can lead to inconsistent formatting.- Parameters:
localeName- The locale to use.
-
invoke
Description copied from interface:ValvePerform request processing as required by this Valve.
An individual Valve MAY perform the following actions, in the specified order:
- Examine and/or modify the properties of the specified Request and Response.
- Examine the properties of the specified Request, completely generate the corresponding Response, and return control to the caller.
- Examine the properties of the specified Request and Response, wrap either or both of these objects to supplement their functionality, and pass them on.
- If the corresponding Response was not generated (and control was not returned), call the next Valve in the
pipeline (if there is one) by executing
getNext().invoke(). - Examine, but not modify, the properties of the resulting Response (which was created by a subsequently invoked Valve or Container).
A Valve MUST NOT do any of the following things:
- Change request properties that have already been used to direct the flow of processing control for this request (for instance, trying to change the virtual host to which a Request should be sent from a pipeline attached to a Host or Context in the standard implementation).
- Create a completed Response AND pass this Request and Response on to the next Valve in the pipeline.
- Consume bytes from the input stream associated with the Request, unless it is completely generating the response, or wrapping the request before passing it on.
- Modify the HTTP headers included with the Response after the
getNext().invoke()method has returned. - Perform any actions on the output stream associated with the specified Response after the
getNext().invoke()method has returned.
- Specified by:
invokein interfaceValve- Parameters:
request- The servlet request to be processedresponse- The servlet response to be created- Throws:
IOException- if an input/output error occurs, or is thrown by a subsequently invoked Valve, Filter, or ServletServletException- if a servlet error occurs, or is thrown by a subsequently invoked Valve, Filter, or Servlet
-
log
Description copied from interface:AccessLogAdd the request/response to the access log using the specified processing time.- Specified by:
login interfaceAccessLog- Parameters:
request- Request (associated with the response) to logresponse- Response (associated with the request) to logtime- 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
-
log
Log the specified message.- Parameters:
message- Message to be logged. This object will be recycled by the calling method.
-
findLocale
-
appendQueryString
protected static void appendQueryString(String query, CharArrayWriter buf, boolean appendDelim, boolean escapeQuoteAsDouble, boolean writeDashOnNull) -
createLogElements
Parse pattern string and create the array of AccessLogElement.- Returns:
- the log elements array
-
createAccessLogElement
Create an AccessLogElement implementation which needs an element name.- Parameters:
name- Header namepattern- char in the log pattern- Returns:
- the log element
-
createAccessLogElement
Create an AccessLogElement implementation.- Parameters:
pattern- char in the log pattern- Returns:
- the log element
-
escapeAndAppend
Escapes and appends the input string to the destination writer.- Parameters:
input- The input stringdest- The destination writer
-
escapeAndAppend
protected static void escapeAndAppend(String input, CharArrayWriter dest, boolean escapeQuoteAsDouble) Escapes and appends the input string to the destination writer.- Parameters:
input- The input stringdest- The destination writerescapeQuoteAsDouble- Whether to escape quotes as double quotes
-