Package org.eclipse.jetty.server
Class CustomRequestLog
- java.lang.Object
-
- org.eclipse.jetty.util.component.AbstractLifeCycle
-
- org.eclipse.jetty.util.component.ContainerLifeCycle
-
- org.eclipse.jetty.server.CustomRequestLog
-
- All Implemented Interfaces:
RequestLog
,Container
,Destroyable
,Dumpable
,Dumpable.DumpableContainer
,LifeCycle
@ManagedObject("Custom format request log") public class CustomRequestLog extends ContainerLifeCycle implements RequestLog
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.
Percent codes are specified in the format %MODIFIERS{PARAM}CODEMODIFIERS: 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
CustomRequestLog
table of format codes.Format Codes Format String Description %% The percent sign. %{format}a Address or Hostname. Valid formats are {server, client, local, remote} Optional format parameter which will be server by default.
Where 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 a proxy between the end-user and the server.%{format}p Port. Valid formats are {server, client, local, remote} Optional format parameter which will be server by default.
Where 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 to a proxy between the end-user and the server.%{CLF}I Size of request in bytes, excluding HTTP headers. Optional parameter with value of "CLF" to use CLF format, i.e. a '-' rather than a 0 when no bytes are sent. %{CLF}O Size of response in bytes, excluding HTTP headers. Optional parameter with value of "CLF" to use CLF format, i.e. a '-' rather than a 0 when no bytes are sent. %{CLF}S Bytes transferred (received and sent). This is the combination of %I and %O. Optional parameter with value of "CLF" to use CLF format, i.e. a '-' rather than a 0 when no bytes are sent. %{VARNAME}C The contents of cookie VARNAME in the request sent to the server. Only version 0 cookies are fully supported. Optional VARNAME parameter, without this parameter %C will log all cookies from the request. %D The time taken to serve the request, in microseconds. %{VARNAME}e The contents of the environment variable VARNAME. %f Filename. %H The request protocol. %{VARNAME}i The contents of VARNAME: header line(s) in the request sent to the server. %k Number of keepalive requests handled on this connection. Interesting if KeepAlive is being used, so that, for example, a '1' means the first keepalive request after the initial one, '2' the second, etc...; otherwise this is always 0 (indicating the initial request). %m The request method. %{VARNAME}o The contents of VARNAME: header line(s) in the response. %q The query string (prepended with a ? if a query string exists, otherwise an empty string). %r First line of request. %R The handler generating the response (if any). %s Response status. %{format|timeZone|locale}t The time that the request was received. Optional parameter in one of the following formats {format}, {format|timeZone} or {format|timeZone|locale}.
Format Parameter: (default format [18/Sep/2011:19:18:28 -0400] where the last number indicates the timezone offset from GMT.) Must be in a format supported by
DateCache
TimeZone Parameter: Default timeZone GMT Must be in a format supported byTimeZone.getTimeZone(String)
Locale Parameter: Default localeLocale.getDefault()
Must be in a format supported byLocale.forLanguageTag(String)
%T The time taken to serve the request, in seconds. %{UNIT}T The time taken to serve the request, in a time unit given by UNIT. Valid units are ms for milliseconds, us for microseconds, and s for seconds. Using s gives the same result as %T without any format; using us gives the same result as %D. %{d}u Remote user if the request was authenticated with servlet authentication. May be bogus if return status (%s) is 401 (unauthorized). Optional parameter d, with this parameter deferred authentication will also be checked, this is equivalent to HttpServletRequest.getRemoteUser()
.%U The URL path requested, not including any query string. %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.
%{VARNAME}^ti The contents of VARNAME: trailer line(s) in the request sent to the server. %{VARNAME}^to The contents of VARNAME: trailer line(s) in the response sent from the server.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
CustomRequestLog.Token
-
Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
AbstractLifeCycle.AbstractLifeCycleListener
-
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
Fields Modifier and Type Field Description private static java.lang.ThreadLocal<java.lang.StringBuilder>
_buffers
private java.lang.String
_formatString
private PathMappings<java.lang.String>
_ignorePathMap
private java.lang.String[]
_ignorePaths
private java.lang.invoke.MethodHandle
_logHandle
private RequestLog.Writer
_requestLogWriter
static java.lang.String
DEFAULT_DATE_FORMAT
static java.lang.String
EXTENDED_NCSA_FORMAT
protected static Logger
LOG
static java.lang.String
NCSA_FORMAT
-
Constructor Summary
Constructors Constructor Description CustomRequestLog(java.lang.String file)
CustomRequestLog(java.lang.String file, java.lang.String format)
CustomRequestLog(RequestLog.Writer writer, java.lang.String formatString)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static void
append(java.lang.StringBuilder buf, java.lang.String s)
private static void
append(java.lang.String s, java.lang.StringBuilder buf)
protected void
doStart()
Set up request logging and open log file.protected static java.lang.String
getAuthentication(Request request, boolean checkDeferred)
Extract the user authenticationjava.lang.String
getFormatString()
Retrieve the format string.java.lang.String[]
getIgnorePaths()
Retrieve the request paths that will not be logged.private java.lang.invoke.MethodHandle
getLogHandle(java.lang.String formatString)
private static java.util.List<CustomRequestLog.Token>
getTokens(java.lang.String formatString)
RequestLog.Writer
getWriter()
void
log(Request request, Response response)
Writes the request and response information to the output stream.private static void
logBytesReceived(java.lang.StringBuilder b, Request request, Response response)
private static void
logBytesReceivedCLF(java.lang.StringBuilder b, Request request, Response response)
private static void
logBytesSent(java.lang.StringBuilder b, Request request, Response response)
private static void
logBytesSentCLF(java.lang.StringBuilder b, Request request, Response response)
private static void
logBytesTransferred(java.lang.StringBuilder b, Request request, Response response)
private static void
logBytesTransferredCLF(java.lang.StringBuilder b, Request request, Response response)
private static void
logClientHost(java.lang.StringBuilder b, Request request, Response response)
private static void
logClientPort(java.lang.StringBuilder b, Request request, Response response)
private static void
logConnectionStatus(java.lang.StringBuilder b, Request request, Response response)
private static void
logEnvironmentVar(java.lang.String arg, java.lang.StringBuilder b, Request request, Response response)
private static void
logFilename(java.lang.StringBuilder b, Request request, Response response)
private static void
logKeepAliveRequests(java.lang.StringBuilder b, Request request, Response response)
private static void
logLatencyMicroseconds(java.lang.StringBuilder b, Request request, Response response)
private static void
logLatencyMilliseconds(java.lang.StringBuilder b, Request request, Response response)
private static void
logLatencySeconds(java.lang.StringBuilder b, Request request, Response response)
private static void
logLocalHost(java.lang.StringBuilder b, Request request, Response response)
private static void
logLocalPort(java.lang.StringBuilder b, Request request, Response response)
private static void
logNothing(java.lang.StringBuilder b, Request request, Response response)
private static void
logQueryString(java.lang.StringBuilder b, Request request, Response response)
private static void
logRemoteHost(java.lang.StringBuilder b, Request request, Response response)
private static void
logRemotePort(java.lang.StringBuilder b, Request request, Response response)
private static void
logRequestAuthentication(java.lang.StringBuilder b, Request request, Response response)
private static void
logRequestAuthenticationWithDeferred(java.lang.StringBuilder b, Request request, Response response)
private static void
logRequestCookie(java.lang.String arg, java.lang.StringBuilder b, Request request, Response response)
private static void
logRequestCookies(java.lang.StringBuilder b, Request request, Response response)
private static void
logRequestFirstLine(java.lang.StringBuilder b, Request request, Response response)
private static void
logRequestHandler(java.lang.StringBuilder b, Request request, Response response)
private static void
logRequestHeader(java.lang.String arg, java.lang.StringBuilder b, Request request, Response response)
private static void
logRequestMethod(java.lang.StringBuilder b, Request request, Response response)
private static void
logRequestProtocol(java.lang.StringBuilder b, Request request, Response response)
private static void
logRequestTime(DateCache dateCache, java.lang.StringBuilder b, Request request, Response response)
private static void
logRequestTrailer(java.lang.String arg, java.lang.StringBuilder b, Request request, Response response)
private static void
logResponseHeader(java.lang.String arg, java.lang.StringBuilder b, Request request, Response response)
private static void
logResponseSize(java.lang.StringBuilder b, Request request, Response response)
private static void
logResponseSizeCLF(java.lang.StringBuilder b, Request request, Response response)
private static void
logResponseStatus(java.lang.StringBuilder b, Request request, Response response)
private static void
logResponseTrailer(java.lang.String arg, java.lang.StringBuilder b, Request request, Response response)
private static void
logServerHost(java.lang.StringBuilder b, Request request, Response response)
private static void
logServerPort(java.lang.StringBuilder b, Request request, Response response)
private static void
logUrlRequestPath(java.lang.StringBuilder b, Request request, Response response)
private static boolean
modify(java.util.List<java.lang.String> modifiers, java.lang.Boolean negated, java.lang.StringBuilder b, Request request, Response response)
void
setIgnorePaths(java.lang.String[] ignorePaths)
Set request paths that will not be logged.private java.lang.invoke.MethodHandle
updateLogHandle(java.lang.invoke.MethodHandle logHandle, java.lang.invoke.MethodHandle append, java.lang.invoke.MethodHandles.Lookup lookup, java.lang.String code, java.lang.String arg, java.util.List<java.lang.String> modifiers, boolean negated)
private java.lang.invoke.MethodHandle
updateLogHandle(java.lang.invoke.MethodHandle logHandle, java.lang.invoke.MethodHandle append, java.lang.String literal)
-
Methods inherited from class org.eclipse.jetty.util.component.ContainerLifeCycle
addBean, addBean, addEventListener, addManaged, contains, destroy, doStop, dump, dump, dump, dump, dump, dumpBeans, dumpObject, dumpObjects, dumpStdErr, dumpThis, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, setStopTimeout, start, stop, unmanage, updateBean, updateBean, updateBeans
-
Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, 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.Dumpable.DumpableContainer
isDumpable
-
-
-
-
Field Detail
-
LOG
protected static final Logger LOG
-
DEFAULT_DATE_FORMAT
public static final java.lang.String DEFAULT_DATE_FORMAT
- See Also:
- Constant Field Values
-
NCSA_FORMAT
public static final java.lang.String NCSA_FORMAT
- See Also:
- Constant Field Values
-
EXTENDED_NCSA_FORMAT
public static final java.lang.String EXTENDED_NCSA_FORMAT
- See Also:
- Constant Field Values
-
_buffers
private static java.lang.ThreadLocal<java.lang.StringBuilder> _buffers
-
_ignorePaths
private java.lang.String[] _ignorePaths
-
_ignorePathMap
private transient PathMappings<java.lang.String> _ignorePathMap
-
_requestLogWriter
private RequestLog.Writer _requestLogWriter
-
_logHandle
private final java.lang.invoke.MethodHandle _logHandle
-
_formatString
private final java.lang.String _formatString
-
-
Constructor Detail
-
CustomRequestLog
public CustomRequestLog(RequestLog.Writer writer, java.lang.String formatString)
-
CustomRequestLog
public CustomRequestLog(java.lang.String file)
-
CustomRequestLog
public CustomRequestLog(java.lang.String file, java.lang.String format)
-
-
Method Detail
-
getWriter
@ManagedAttribute("The RequestLogWriter") public RequestLog.Writer getWriter()
-
log
public void log(Request request, Response response)
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:
RequestLog.log(Request, Response)
-
getAuthentication
protected static java.lang.String getAuthentication(Request request, boolean checkDeferred)
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
public void setIgnorePaths(java.lang.String[] ignorePaths)
Set request paths that will not be logged.- Parameters:
ignorePaths
- array of request paths
-
getIgnorePaths
public java.lang.String[] getIgnorePaths()
Retrieve the request paths that will not be logged.- Returns:
- array of request paths
-
getFormatString
@ManagedAttribute("format string") public java.lang.String getFormatString()
Retrieve the format string.- Returns:
- the format string
-
doStart
protected void doStart() throws java.lang.Exception
Set up request logging and open log file.- Overrides:
doStart
in classContainerLifeCycle
- Throws:
java.lang.Exception
- See Also:
AbstractLifeCycle.doStart()
-
append
private static void append(java.lang.StringBuilder buf, java.lang.String s)
-
append
private static void append(java.lang.String s, java.lang.StringBuilder buf)
-
getLogHandle
private java.lang.invoke.MethodHandle getLogHandle(java.lang.String formatString) throws java.lang.NoSuchMethodException, java.lang.IllegalAccessException
- Throws:
java.lang.NoSuchMethodException
java.lang.IllegalAccessException
-
getTokens
private static java.util.List<CustomRequestLog.Token> getTokens(java.lang.String formatString)
-
updateLogHandle
private java.lang.invoke.MethodHandle updateLogHandle(java.lang.invoke.MethodHandle logHandle, java.lang.invoke.MethodHandle append, java.lang.String literal)
-
modify
private static boolean modify(java.util.List<java.lang.String> modifiers, java.lang.Boolean negated, java.lang.StringBuilder b, Request request, Response response)
-
updateLogHandle
private java.lang.invoke.MethodHandle updateLogHandle(java.lang.invoke.MethodHandle logHandle, java.lang.invoke.MethodHandle append, java.lang.invoke.MethodHandles.Lookup lookup, java.lang.String code, java.lang.String arg, java.util.List<java.lang.String> modifiers, boolean negated) throws java.lang.NoSuchMethodException, java.lang.IllegalAccessException
- Throws:
java.lang.NoSuchMethodException
java.lang.IllegalAccessException
-
logNothing
private static void logNothing(java.lang.StringBuilder b, Request request, Response response)
-
logServerHost
private static void logServerHost(java.lang.StringBuilder b, Request request, Response response)
-
logClientHost
private static void logClientHost(java.lang.StringBuilder b, Request request, Response response)
-
logLocalHost
private static void logLocalHost(java.lang.StringBuilder b, Request request, Response response)
-
logRemoteHost
private static void logRemoteHost(java.lang.StringBuilder b, Request request, Response response)
-
logServerPort
private static void logServerPort(java.lang.StringBuilder b, Request request, Response response)
-
logClientPort
private static void logClientPort(java.lang.StringBuilder b, Request request, Response response)
-
logLocalPort
private static void logLocalPort(java.lang.StringBuilder b, Request request, Response response)
-
logRemotePort
private static void logRemotePort(java.lang.StringBuilder b, Request request, Response response)
-
logResponseSize
private static void logResponseSize(java.lang.StringBuilder b, Request request, Response response)
-
logResponseSizeCLF
private static void logResponseSizeCLF(java.lang.StringBuilder b, Request request, Response response)
-
logBytesSent
private static void logBytesSent(java.lang.StringBuilder b, Request request, Response response)
-
logBytesSentCLF
private static void logBytesSentCLF(java.lang.StringBuilder b, Request request, Response response)
-
logBytesReceived
private static void logBytesReceived(java.lang.StringBuilder b, Request request, Response response)
-
logBytesReceivedCLF
private static void logBytesReceivedCLF(java.lang.StringBuilder b, Request request, Response response)
-
logBytesTransferred
private static void logBytesTransferred(java.lang.StringBuilder b, Request request, Response response)
-
logBytesTransferredCLF
private static void logBytesTransferredCLF(java.lang.StringBuilder b, Request request, Response response)
-
logRequestCookie
private static void logRequestCookie(java.lang.String arg, java.lang.StringBuilder b, Request request, Response response)
-
logRequestCookies
private static void logRequestCookies(java.lang.StringBuilder b, Request request, Response response)
-
logEnvironmentVar
private static void logEnvironmentVar(java.lang.String arg, java.lang.StringBuilder b, Request request, Response response)
-
logFilename
private static void logFilename(java.lang.StringBuilder b, Request request, Response response)
-
logRequestProtocol
private static void logRequestProtocol(java.lang.StringBuilder b, Request request, Response response)
-
logRequestHeader
private static void logRequestHeader(java.lang.String arg, java.lang.StringBuilder b, Request request, Response response)
-
logKeepAliveRequests
private static void logKeepAliveRequests(java.lang.StringBuilder b, Request request, Response response)
-
logRequestMethod
private static void logRequestMethod(java.lang.StringBuilder b, Request request, Response response)
-
logResponseHeader
private static void logResponseHeader(java.lang.String arg, java.lang.StringBuilder b, Request request, Response response)
-
logQueryString
private static void logQueryString(java.lang.StringBuilder b, Request request, Response response)
-
logRequestFirstLine
private static void logRequestFirstLine(java.lang.StringBuilder b, Request request, Response response)
-
logRequestHandler
private static void logRequestHandler(java.lang.StringBuilder b, Request request, Response response)
-
logResponseStatus
private static void logResponseStatus(java.lang.StringBuilder b, Request request, Response response)
-
logRequestTime
private static void logRequestTime(DateCache dateCache, java.lang.StringBuilder b, Request request, Response response)
-
logLatencyMicroseconds
private static void logLatencyMicroseconds(java.lang.StringBuilder b, Request request, Response response)
-
logLatencyMilliseconds
private static void logLatencyMilliseconds(java.lang.StringBuilder b, Request request, Response response)
-
logLatencySeconds
private static void logLatencySeconds(java.lang.StringBuilder b, Request request, Response response)
-
logRequestAuthentication
private static void logRequestAuthentication(java.lang.StringBuilder b, Request request, Response response)
-
logRequestAuthenticationWithDeferred
private static void logRequestAuthenticationWithDeferred(java.lang.StringBuilder b, Request request, Response response)
-
logUrlRequestPath
private static void logUrlRequestPath(java.lang.StringBuilder b, Request request, Response response)
-
logConnectionStatus
private static void logConnectionStatus(java.lang.StringBuilder b, Request request, Response response)
-
logRequestTrailer
private static void logRequestTrailer(java.lang.String arg, java.lang.StringBuilder b, Request request, Response response)
-
-