Top Description Inners Fields Constructors Methods
org.eclipse.jetty.server

public Class CustomRequestLog

extends ContainerLifeCycle
implements RequestLog
Class Inheritance
All Implemented Interfaces
org.eclipse.jetty.server.RequestLog
Annotations
@ManagedObject:Custom format request log
Imports
java.lang.invoke.MethodHandle, .MethodHandles, .MethodType, java.security.Principal, java.util.ArrayList, .Collections, .List, .Locale, .TimeZone, java.util.concurrent.TimeUnit, java.util.function.BiPredicate, .Supplier, java.util.regex.Matcher, .Pattern, java.util.stream.Collectors, org.eclipse.jetty.http.HttpCookie, .HttpFields, .QuotedCSV, org.eclipse.jetty.http.pathmap.PathMappings, org.eclipse.jetty.util.DateCache, .NanoTime, .StringUtil, org.eclipse.jetty.util.annotation.ManagedAttribute, .ManagedObject, org.eclipse.jetty.util.component.ContainerLifeCycle, org.eclipse.jetty.util.resource.Resource, org.slf4j.Logger, .LoggerFactory

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 Codes
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 - rather than a 0 when no bytes are present.

%{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 - rather than a 0 when no bytes are present.

%{CLF}S

The bytes transferred (received and sent). This is the combination of %I and %O.

The parameter is optional. When the parameter value is "CLF" the Common Log Format is used, i.e. a - rather than a 0 when no bytes are present.

%{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}.

format
Default is e.g. [18/Sep/2011:19:18:28 -0400] where the last number indicates the timezone offset from GMT. Must be in a format supported by the java.time package.
timeZone
Default is GMT. Must be in a format supported by the java.time package.
locale
Default is the JVM default locale. Must be in a format supported by java.util.Locale.forLanguageTag().
%{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. %{us}T is identical to %D.

%{d}u

The remote user if the request was authenticated with servlet authentication.

May be an invalid value if response status code (%s) is 401 (unauthorized).

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:

X
The connection is aborted before the response completed.
+
The connection may be kept alive after the response is sent.
-
The connection will be closed after the response is sent.
%{VARNAME}ti

The value of the VARNAME request trailer.

%{VARNAME}to

The value of the VARNAME response trailer.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static record
CustomRequestLog.LogDetail

Record holding extra detail for logging

private static class

Field Summary

Modifier and TypeField and Description
private static final ThreadLocal<StringBuilder>
private BiPredicate<Request, Response>
private final String
private transient PathMappings<String>
private String[]
private final MethodHandle
private final RequestLog.Writer
public static final String
public static final String
private static final Logger
public static final String
public static final String

Constructor Summary

AccessConstructor and Description
public
public
public
public
CustomRequestLog(RequestLog.Writer writer, String formatString)

Method Summary

Modifier and TypeMethod and Description
private static void
private static void
protected void
doStart()

Overrides org.eclipse.jetty.util.component.ContainerLifeCycle.doStart.

Set up request logging and open log file.

public String

Returns:

the format string
getFormatString
()

Retrieve the format string.

public String[]

Returns:

array of request paths
getIgnorePaths
()

Retrieve the request paths that will not be logged.

private MethodHandle
getLogHandle(String formatString)

private static List<CustomRequestLog.Token>
getTokens(String formatString)

public RequestLog.Writer
public void
log(Request
The request to log.
request
,
Response
The response to log.
response
)

Implements org.eclipse.jetty.server.RequestLog.log.

private static void
private static void
private static void
private static void
private static void
private static void
private static void
private static void
private static void
private static void
private static void
logFilename(StringBuilder b, Request request, Response response)

private static void
private static void
private static void
private static void
private static void
private static void
private static void
private static void
logNothing(StringBuilder b, Request request, Response response)

private static void
private static void
private static void
private static void
private static void
private static void
private static void
private static void
private static void
private static void
private static void
private static void
private static void
logRequestTime(DateCache dateCache, StringBuilder b, Request request, Response response)

private static void
private static void
private static void
private static void
private static void
private static void
private static void
private static void
private static void
private static boolean
modify(List<Integer> modifiers, Boolean negated, StringBuilder b, Request request, Response response)

public void
setFilter(BiPredicate<Request, Response>
- a BiPredicate which returns true if this request should be logged.
filter
)

This allows you to set a custom filter to decide whether to log a request or omit it from the request log.

public void
setIgnorePaths(String[]
array of request paths
ignorePaths
)

Set request paths that will not be logged.

private MethodHandle
updateLogHandle(MethodHandle logHandle, MethodHandle append, String literal)

private MethodHandle
updateLogHandle(MethodHandle logHandle, MethodHandle append, MethodHandles.Lookup lookup, String code, String arg, List<Integer> modifiers, boolean negated)

Inherited from org.eclipse.jetty.util.component.ContainerLifeCycle:
addBeanaddBeanaddEventListeneraddManagedcontainsdestroydoStopdumpdumpdumpdumpObjectsdumpStdErrgetBeangetBeansgetBeansgetContainedBeansgetContainedBeansisAutoisManagedisUnmanagedmanageremoveBeanremoveBeansremoveEventListenersetBeansstartstopunmanageupdateBeanupdateBeanupdateBeansupdateBeans