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:
enableLookups
for the connector is false)
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)
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
AccessLogElement writes the partial message into the buffer.
|
protected static class |
AbstractAccessLogValve.ByteSentElement
write bytes sent, excluding HTTP headers - %b, %B
|
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
|
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 static class |
AbstractAccessLogValve.LocalServerNameElement
write local server name - %v
|
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
|
protected class |
AbstractAccessLogValve.ProtocolElement
write request protocol - %H
|
protected static class |
AbstractAccessLogValve.QueryElement
write Query string (prepended with a '?'
|
protected class |
AbstractAccessLogValve.RemoteAddrElement
write remote IP address - %a
|
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 |
AbstractAccessLogValve.StringElement
write any string
|
protected static class |
AbstractAccessLogValve.ThreadNameElement
write thread name - %I
|
protected static class |
AbstractAccessLogValve.UserElement
write remote user that was authenticated (if any), else '-' - %u
|
Lifecycle.SingleUse
Modifier and Type | Field and Description |
---|---|
protected java.lang.String |
condition
Are we doing conditional logging. default null.
|
protected java.lang.String |
conditionIf
Are we doing conditional logging. default null.
|
protected boolean |
enabled
enabled this component
|
protected java.util.Locale |
locale
Locale used to format timestamps in log entries and in
log file name suffix.
|
protected java.lang.String |
localeName
Name of locale used to format timestamps in log entries and in
log file name suffix.
|
protected AbstractAccessLogValve.AccessLogElement[] |
logElements
Array of AccessLogElement, they will be used to make log message.
|
protected java.lang.String |
pattern
The pattern used to format our access log lines.
|
protected boolean |
requestAttributesEnabled
Should this valve set request attributes for IP address, hostname,
protocol and port used for the request.
|
asyncSupported, container, containerLog, next, sm
mserver
PROTOCOL_ATTRIBUTE, REMOTE_ADDR_ATTRIBUTE, REMOTE_HOST_ATTRIBUTE, SERVER_PORT_ATTRIBUTE
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 and Description |
---|
AbstractAccessLogValve() |
Modifier and Type | Method and Description |
---|---|
protected AbstractAccessLogValve.AccessLogElement |
createAccessLogElement(char pattern)
create an AccessLogElement implementation
|
protected AbstractAccessLogValve.AccessLogElement |
createAccessLogElement(java.lang.String name,
char pattern)
create an AccessLogElement implementation which needs an element name
|
protected AbstractAccessLogValve.AccessLogElement[] |
createLogElements()
parse pattern string and create the array of AccessLogElement
|
protected static java.util.Locale |
findLocale(java.lang.String name,
java.util.Locale fallback)
Find a locale by name
|
java.lang.String |
getCondition()
Return whether the attribute name to look for when
performing conditional logging.
|
java.lang.String |
getConditionIf()
Return whether the attribute name to look for when
performing conditional logging.
|
java.lang.String |
getConditionUnless()
Return whether the attribute name to look for when
performing conditional logging.
|
boolean |
getEnabled() |
java.lang.String |
getLocale()
Return the locale used to format timestamps in log entries and in
log file name suffix.
|
java.lang.String |
getPattern()
Return the format pattern.
|
boolean |
getRequestAttributesEnabled() |
void |
invoke(Request request,
Response response)
Log a message summarizing the specified request and response, according
to the format specified by the
pattern property. |
protected abstract void |
log(java.io.CharArrayWriter message)
Log the specified message.
|
void |
log(Request request,
Response response,
long time)
Add the request/response to the access log using the specified processing
time.
|
void |
setCondition(java.lang.String condition)
Set the ServletRequest.attribute to look for to perform
conditional logging.
|
void |
setConditionIf(java.lang.String condition)
Set the ServletRequest.attribute to look for to perform
conditional logging.
|
void |
setConditionUnless(java.lang.String condition)
Set the ServletRequest.attribute to look for to perform
conditional logging.
|
void |
setEnabled(boolean enabled) |
void |
setLocale(java.lang.String localeName)
Set the locale used to format timestamps in log entries and in
log file name suffix.
|
void |
setPattern(java.lang.String pattern)
Set the format pattern, first translating any recognized alias.
|
void |
setRequestAttributesEnabled(boolean requestAttributesEnabled)
Should this valve set request attributes for IP address, hostname,
protocol and port used for the request?
|
protected void |
startInternal()
Start this component and implement the requirements
of
LifecycleBase.startInternal() . |
protected void |
stopInternal()
Stop this component and implement the requirements
of
LifecycleBase.stopInternal() . |
backgroundProcess, event, getContainer, getDomainInternal, getNext, getObjectNameKeyProperties, initInternal, isAsyncSupported, setAsyncSupported, setContainer, setNext, toString
destroyInternal, getDomain, getObjectName, postDeregister, postRegister, preDeregister, preRegister, register, setDomain, unregister
addLifecycleListener, destroy, findLifecycleListeners, fireLifecycleEvent, getState, getStateName, init, removeLifecycleListener, setState, setState, start, stop
protected boolean enabled
protected java.lang.String pattern
protected java.lang.String condition
conditionUnless
property.protected java.lang.String conditionIf
conditionIf
property.protected java.lang.String localeName
protected java.util.Locale locale
protected AbstractAccessLogValve.AccessLogElement[] logElements
protected boolean requestAttributesEnabled
false
.setRequestAttributesEnabled(boolean)
public void setRequestAttributesEnabled(boolean requestAttributesEnabled)
AccessLogValve
which will otherwise log the original values.
The attributes set are:
false
.setRequestAttributesEnabled
in interface AccessLog
requestAttributesEnabled
- true
causes the attributes
to be set, false
disables
the setting of the attributes.public boolean getRequestAttributesEnabled()
getRequestAttributesEnabled
in interface AccessLog
true
if the attributes will be logged, otherwise
false
AccessLog.setRequestAttributesEnabled(boolean)
public boolean getEnabled()
public void setEnabled(boolean enabled)
enabled
- The enabled to set.public java.lang.String getPattern()
public void setPattern(java.lang.String pattern)
pattern
- The new patternpublic java.lang.String getCondition()
public void setCondition(java.lang.String condition)
condition
- Set to null to log everythingpublic java.lang.String getConditionUnless()
public void setConditionUnless(java.lang.String condition)
condition
- Set to null to log everythingpublic java.lang.String getConditionIf()
public void setConditionIf(java.lang.String condition)
condition
- Set to null to log everythingpublic java.lang.String getLocale()
public void setLocale(java.lang.String localeName)
localeName
- The locale to use.public void invoke(Request request, Response response) throws java.io.IOException, ServletException
pattern
property.invoke
in interface Valve
invoke
in class ValveBase
request
- Request being processedresponse
- Response being processedjava.io.IOException
- if an input/output error has occurredServletException
- if a servlet error has occurredpublic void log(Request request, Response response, long time)
AccessLog
protected abstract void log(java.io.CharArrayWriter message)
message
- Message to be logged. This object will be recycled by
the calling method.protected static java.util.Locale findLocale(java.lang.String name, java.util.Locale fallback)
protected void startInternal() throws LifecycleException
LifecycleBase.startInternal()
.startInternal
in class ValveBase
LifecycleException
- if this component detects a fatal error
that prevents this component from being usedprotected void stopInternal() throws LifecycleException
LifecycleBase.stopInternal()
.stopInternal
in class ValveBase
LifecycleException
- if this component detects a fatal error
that prevents this component from being usedprotected AbstractAccessLogValve.AccessLogElement[] createLogElements()
protected AbstractAccessLogValve.AccessLogElement createAccessLogElement(java.lang.String name, char pattern)
protected AbstractAccessLogValve.AccessLogElement createAccessLogElement(char pattern)
Copyright © 2000-2018 Apache Software Foundation. All Rights Reserved.