Class CustomRequestLog
- All Implemented Interfaces:
RequestLog
,Container
,Destroyable
,Dumpable
,Dumpable.DumpableContainer
,LifeCycle
A flexible RequestLog, which produces log strings in a customizable format.
The Logger takes a format string where request characteristics can be added using "%" format codes which are replaced by the corresponding value in the log output.
The terms server, client, local and remote are used to refer to the different addresses and ports which can be logged. Server and client refer to the logical addresses which can be modified in the request headers. Where local and remote refer to the physical addresses which may be a proxy between the end-user and the server.
Format codes are specified with the syntax %MODIFIERS{PARAM}CODE
as follows:
- MODIFIERS
- Optional list of comma separated HTTP status codes which may be preceded by a single "!" to indicate negation. If the status code is not in the list the literal string "-" will be logged instead of the resulting value from the percent code.
- {PARAM}
- Parameter string which may be optional depending on the percent code used.
- CODE
- A one or two character code specified by the table of format codes below.
Format String | Description |
---|---|
X |
The X character. |
%% |
The percent character. |
%{format}a |
The address or host name. Valid format values are: "server", "client", "local", "remote". The format parameter is optional and defaults to "server". Values "server" and "client" are the logical addresses which can be modified in the request headers, while "local" and "remote" are the physical addresses so may be the addresses of a proxy between the end-user and the server. |
%{format}p |
The port. Valid format values are: "server", "client", "local", "remote". The format parameter is optional and defaults to "server". Values "server" and "client" are the logical ports which can be modified in the request headers, while "local" and "remote" are the physical ports so may be the ports of a proxy between the end-user and the server. |
%{CLF}I |
The size of request in bytes, excluding HTTP headers. The parameter is optional.
When the parameter value is "CLF" the Common Log Format is used, i.e. a |
%{CLF}O |
The size of response in bytes, excluding HTTP headers. The parameter is optional.
When the parameter value is "CLF" the Common Log Format is used, i.e. a |
%{CLF}S |
The bytes transferred (received and sent). This is the combination of The parameter is optional.
When the parameter value is "CLF" the Common Log Format is used, i.e. a |
%{VARNAME}C |
The value of the request cookie VARNAME. The parameter is optional. Only version 0 cookies are fully supported. When the parameter is missing, all request cookies will be logged. |
%D |
The time taken to serve the request, in microseconds. |
%{VARNAME}e |
The value of the environment variable VARNAME. |
%f |
The file system path of the requested resource. |
%H |
The name and version of the request protocol, such as "HTTP/1.1". |
%{VARNAME}i |
The value of the VARNAME request header. |
%k |
The number of requests handled on a connection. The initial request on a connection yields a value 0, the first request after the initial on the same connection yields the value 1, the second request on the same connection yields the value 2, etc. |
%m |
The HTTP request method. |
%{VARNAME}o |
The value of the VARNAME response header. |
%q |
The query string, prepended with a ? if a query string exists, otherwise an empty string. |
%r |
First line of an HTTP/1.1 request (or equivalent information for HTTP/2 or later). |
%R |
The name of the Handler or Servlet generating the response (if any). |
%s |
The HTTP response status code. |
%{format|timeZone|locale}t |
The time at which the request was received. The parameter is optional and may have the following values: {format}, {format|timeZone} or {format|timeZone|locale}.
|
%{UNIT}T |
The time taken to serve the request. The parameter UNIT is optional and defaults to "s".
The parameter UNIT indicates the unit of time: "s" for seconds, "ms" for milliseconds, "us" for microseconds.
|
%{d}u |
The remote user if the request was authenticated with servlet authentication. May be an invalid value if response status code ( The parameter is optional. When the parameter value is "d", deferred authentication will also be checked. |
%U |
The URL path requested, not including any query string. |
%X |
The connection status when response is completed:
|
%{VARNAME}ti |
The value of the VARNAME request trailer. |
%{VARNAME}to |
The value of the VARNAME response trailer. |
-
Nested Class Summary
Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
AbstractLifeCycle.AbstractLifeCycleListener, AbstractLifeCycle.StopException
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Container
Container.InheritedListener, Container.Listener
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Dumpable
Dumpable.DumpableContainer
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle
LifeCycle.Listener
Nested classes/interfaces inherited from interface org.eclipse.jetty.server.RequestLog
RequestLog.Collection, RequestLog.Writer
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
static final String
protected static final org.slf4j.Logger
static final String
-
Constructor Summary
ConstructorDescriptionCustomRequestLog
(String file) CustomRequestLog
(String file, String format) CustomRequestLog
(RequestLog.Writer writer, String formatString) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
doStart()
Set up request logging and open log file.protected static String
getAuthentication
(Request request, boolean checkDeferred) Extract the user authenticationRetrieve the format string.String[]
Retrieve the request paths that will not be logged.void
Writes the request and response information to the output stream.void
setFilter
(BiPredicate<Request, Response> filter) This allows you to set a custom filter to decide whether to log a request or omit it from the request log.void
setIgnorePaths
(String[] ignorePaths) Set request paths that will not be logged.Methods inherited from class org.eclipse.jetty.util.component.ContainerLifeCycle
addBean, addBean, addEventListener, addManaged, contains, destroy, doStop, dump, dump, dump, dumpObjects, dumpStdErr, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, start, stop, unmanage, updateBean, updateBean, updateBeans, updateBeans
Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
getEventListeners, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, setEventListeners, start, stop, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.eclipse.jetty.util.component.Container
getCachedBeans, getEventListeners
Methods inherited from interface org.eclipse.jetty.util.component.Dumpable.DumpableContainer
isDumpable
-
Field Details
-
LOG
protected static final org.slf4j.Logger LOG -
DEFAULT_DATE_FORMAT
- See Also:
-
NCSA_FORMAT
- See Also:
-
EXTENDED_NCSA_FORMAT
- See Also:
-
-
Constructor Details
-
CustomRequestLog
public CustomRequestLog() -
CustomRequestLog
-
CustomRequestLog
-
CustomRequestLog
-
-
Method Details
-
setFilter
This allows you to set a custom filter to decide whether to log a request or omit it from the request log. This filter is evaluated after path filtering is applied fromsetIgnorePaths(String[])
.- Parameters:
filter
- - a BiPredicate which returns true if this request should be logged.
-
getWriter
-
log
Writes the request and response information to the output stream.- Specified by:
log
in interfaceRequestLog
- Parameters:
request
- The request to log.response
- The response to log. Note that for some requests the response instance may not have been fully populated (Eg 400 bad request responses are sent without a servlet response object). Thus for basic log information it is best to consultResponse.getCommittedMetaData()
andResponse.getHttpChannel()
directly.- See Also:
-
getAuthentication
Extract the user authentication- Parameters:
request
- The request to extract fromcheckDeferred
- Whether to check for deferred authentication- Returns:
- The string to log for authenticated user.
-
setIgnorePaths
Set request paths that will not be logged.- Parameters:
ignorePaths
- array of request paths
-
getIgnorePaths
Retrieve the request paths that will not be logged.- Returns:
- array of request paths
-
getFormatString
Retrieve the format string.- Returns:
- the format string
-
doStart
Set up request logging and open log file.- Overrides:
doStart
in classContainerLifeCycle
- Throws:
AbstractLifeCycle.StopException
- If thrown, the lifecycle will immediately be stopped.Exception
- If there was a problem starting. Will cause a transition to FAILED state- See Also:
-