Issue #113 - reformat, javadoc update and changes after review
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
parent
2cd579353c
commit
b35df419bb
|
@ -17,22 +17,22 @@
|
|||
<New class="org.eclipse.jetty.server.AsyncRequestLogWriter">
|
||||
<Arg><Property name="jetty.base" default="." />/<Property>
|
||||
<Name>jetty.customrequestlog.filePath</Name>
|
||||
<Default><Property name="jetty.customrequestlog.dir" default="logs"/>/yyyy_mm_dd.request.log</Default>
|
||||
<Default><Property name="jetty.requestlog.dir" default="logs"/>/yyyy_mm_dd.request.log</Default>
|
||||
</Property></Arg>
|
||||
<Arg/>
|
||||
|
||||
<Set name="filenameDateFormat"><Property name="jetty.customrequestlog.filenameDateFormat" default="yyyy_MM_dd"/></Set>
|
||||
<Set name="retainDays"><Property name="jetty.customrequestlog.retainDays" default="90"/></Set>
|
||||
<Set name="append"><Property name="jetty.customrequestlog.append" default="false"/></Set>
|
||||
<Set name="timeZone"><Property name="jetty.customrequestlog.timezone" default="GMT"/></Set>
|
||||
<Set name="filenameDateFormat"><Property name="jetty.requestlog.filenameDateFormat" default="yyyy_MM_dd"/></Set>
|
||||
<Set name="retainDays"><Property name="jetty.requestlog.retainDays" default="90"/></Set>
|
||||
<Set name="append"><Property name="jetty.requestlog.append" default="false"/></Set>
|
||||
<Set name="timeZone"><Property name="jetty.requestlog.timezone" default="GMT"/></Set>
|
||||
</New>
|
||||
</Arg>
|
||||
|
||||
<!-- Format String -->
|
||||
<Arg>
|
||||
<Property name="jetty.customrequestlog.formatString">
|
||||
<Property name="jetty.requestlog.formatString">
|
||||
<Default>
|
||||
<Get class="org.eclipse.jetty.server.CustomRequestLog" name="NCSA_FORMAT"/>
|
||||
<Get class="org.eclipse.jetty.server.CustomRequestLog" name="EXTENDED_NCSA_FORMAT"/>
|
||||
</Default>
|
||||
</Property>
|
||||
</Arg>
|
||||
|
|
|
@ -7,7 +7,7 @@ Enables a format string style request log.
|
|||
requestlog
|
||||
|
||||
[tags]
|
||||
customrequestlog
|
||||
requestlog
|
||||
|
||||
[depend]
|
||||
server
|
||||
|
@ -20,22 +20,22 @@ logs/
|
|||
|
||||
[ini-template]
|
||||
## Logging directory (relative to $jetty.base)
|
||||
# jetty.customrequestlog.dir=logs
|
||||
# jetty.requestlog.dir=logs
|
||||
|
||||
## File path
|
||||
# jetty.customrequestlog.filePath=${jetty.customrequestlog.dir}/yyyy_mm_dd.request.log
|
||||
# jetty.requestlog.filePath=${jetty.requestlog.dir}/yyyy_mm_dd.request.log
|
||||
|
||||
## Date format for rollovered files (uses SimpleDateFormat syntax)
|
||||
# jetty.customrequestlog.filenameDateFormat=yyyy_MM_dd
|
||||
# jetty.requestlog.filenameDateFormat=yyyy_MM_dd
|
||||
|
||||
## How many days to retain old log files
|
||||
# jetty.customrequestlog.retainDays=90
|
||||
# jetty.requestlog.retainDays=90
|
||||
|
||||
## Whether to append to existing file
|
||||
# jetty.customrequestlog.append=false
|
||||
# jetty.requestlog.append=false
|
||||
|
||||
## Timezone of the log entries
|
||||
# jetty.customrequestlog.timezone=GMT
|
||||
# jetty.requestlog.timezone=GMT
|
||||
|
||||
## Format string
|
||||
# jetty.customrequestlog.formatString=%a - %u %t "%r" %s %B "%{Referer}i" "%{User-Agent}i" "%C"
|
||||
# jetty.requestlog.formatString=%a - %u %t "%r" %s %B "%{Referer}i" "%{User-Agent}i" "%C"
|
||||
|
|
|
@ -20,6 +20,7 @@ package org.eclipse.jetty.server;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.servlet.http.Cookie;
|
||||
|
||||
import org.eclipse.jetty.http.HttpHeader;
|
||||
|
@ -36,7 +37,8 @@ import org.eclipse.jetty.util.log.Logger;
|
|||
* Configuration options allow a choice between the standard Common Log Format (as used in the 3 log format) and the
|
||||
* Combined Log Format (single log format). This log format can be output by most web servers, and almost all web log
|
||||
* analysis software can understand these formats.
|
||||
* @deprecated use {@link CustomRequestLog} given format string {@link CustomRequestLog#NCSA_FORMAT} with a {@link RequestLog.Writer}
|
||||
*
|
||||
* @deprecated use {@link CustomRequestLog} given format string {@link CustomRequestLog#EXTENDED_NCSA_FORMAT} with a {@link RequestLog.Writer}
|
||||
*/
|
||||
@Deprecated
|
||||
public class AbstractNCSARequestLog extends ContainerLifeCycle implements RequestLog
|
||||
|
@ -67,6 +69,7 @@ public class AbstractNCSARequestLog extends ContainerLifeCycle implements Reques
|
|||
|
||||
/**
|
||||
* Is logging enabled
|
||||
*
|
||||
* @return true if logging is enabled
|
||||
*/
|
||||
protected boolean isEnabled()
|
||||
|
@ -76,6 +79,7 @@ public class AbstractNCSARequestLog extends ContainerLifeCycle implements Reques
|
|||
|
||||
/**
|
||||
* Write requestEntry out. (to disk or slf4j log)
|
||||
*
|
||||
* @param requestEntry the request entry
|
||||
* @throws IOException if unable to write the entry
|
||||
*/
|
||||
|
@ -225,6 +229,7 @@ public class AbstractNCSARequestLog extends ContainerLifeCycle implements Reques
|
|||
|
||||
/**
|
||||
* Extract the user authentication
|
||||
*
|
||||
* @param request The request to extract from
|
||||
* @return The string to log for authenticated user.
|
||||
*/
|
||||
|
|
|
@ -22,7 +22,7 @@ import java.util.concurrent.BlockingQueue;
|
|||
|
||||
/**
|
||||
* An asynchronously writing NCSA Request Log
|
||||
* @deprecated use {@link CustomRequestLog} given format string {@link CustomRequestLog#NCSA_FORMAT} with an {@link AsyncRequestLogWriter}
|
||||
* @deprecated use {@link CustomRequestLog} given format string {@link CustomRequestLog#EXTENDED_NCSA_FORMAT} with an {@link AsyncRequestLogWriter}
|
||||
*/
|
||||
@Deprecated
|
||||
public class AsyncNCSARequestLog extends NCSARequestLog
|
||||
|
|
|
@ -26,6 +26,10 @@ import org.eclipse.jetty.util.BlockingArrayQueue;
|
|||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
|
||||
|
||||
/**
|
||||
* An asynchronously writing RequestLogWriter
|
||||
*/
|
||||
public class AsyncRequestLogWriter extends RequestLogWriter
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(AsyncRequestLogWriter.class);
|
||||
|
|
|
@ -29,6 +29,7 @@ import java.util.concurrent.TimeUnit;
|
|||
import java.util.function.Supplier;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.servlet.http.Cookie;
|
||||
|
||||
import org.eclipse.jetty.http.HttpFields;
|
||||
|
@ -37,6 +38,7 @@ import org.eclipse.jetty.http.pathmap.PathMappings;
|
|||
import org.eclipse.jetty.server.handler.ContextHandler;
|
||||
import org.eclipse.jetty.util.DateCache;
|
||||
import org.eclipse.jetty.util.annotation.ManagedAttribute;
|
||||
import org.eclipse.jetty.util.annotation.ManagedObject;
|
||||
import org.eclipse.jetty.util.component.ContainerLifeCycle;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
|
@ -46,237 +48,223 @@ import static java.lang.invoke.MethodHandles.foldArguments;
|
|||
import static java.lang.invoke.MethodType.methodType;
|
||||
|
||||
/**
|
||||
<table>
|
||||
<caption>CustomRequestLog Format Codes</caption>
|
||||
<tr>
|
||||
<td><b>Format String</b></td>
|
||||
<td><b>Description</b></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>%%</td>
|
||||
<td>The percent sign.</td>
|
||||
</tr>
|
||||
|
||||
|
||||
|
||||
|
||||
<tr>
|
||||
<td valign="top">%{format}a</td>
|
||||
<td>
|
||||
Client IP address of the request.
|
||||
Valid formats are {server, client, local, remote}
|
||||
|
||||
where server and client are the logical addresses
|
||||
where local and remote are the physical addresses
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
|
||||
|
||||
<tr>
|
||||
<td valign="top">%a</td>
|
||||
<td>Client IP address of the request.</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td valign="top">%{c}a</td>
|
||||
<td>Underlying peer IP address of the connection.</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td valign="top">%A</td>
|
||||
<td>Local IP-address.</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td valign="top">%h</td>
|
||||
<td>Remote hostname. Will log a dotted-string form of the IP if the Hostname cannot be resolved.</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td valign="top">%v</td>
|
||||
<td>
|
||||
todo this is now %{server}a
|
||||
The canonical ServerName of the server serving the request.</td>
|
||||
</tr>
|
||||
|
||||
|
||||
<tr>
|
||||
<td valign="top">%B</td>
|
||||
<td>Size of response in bytes, excluding HTTP headers.</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td valign="top">%b</td>
|
||||
<td>Size of response in bytes, excluding HTTP headers. In CLF format, i.e. a '-' rather than a 0 when no bytes are sent.</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td valign="top">%{VARNAME}C</td>
|
||||
<td>
|
||||
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.
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td valign="top">%D</td>
|
||||
<td>The time taken to serve the request, in microseconds.</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td valign="top">%{VARNAME}e</td>
|
||||
<td>The contents of the environment variable VARNAME.</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td valign="top">%f</td>
|
||||
<td>Filename.</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td valign="top">%H</td>
|
||||
<td>The request protocol.</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td valign="top">%{VARNAME}i</td>
|
||||
<td>The contents of VARNAME: header line(s) in the request sent to the server.</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td valign="top">%k</td>
|
||||
<td>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).</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td valign="top">%m</td>
|
||||
<td>The request method.</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td valign="top">%{VARNAME}o</td>
|
||||
<td>The contents of VARNAME: header line(s) in the response.</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td valign="top">%p</td>
|
||||
<td>The canonical port of the server serving the request.
|
||||
todo merge this with below
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="top">%{format}p</td>
|
||||
<td>The canonical port of the server serving the request, or the server's actual port, or the client's actual port.
|
||||
Valid formats are canonical, local, or remote.
|
||||
todo update this documenatation
|
||||
server, client logical
|
||||
local, remote physical
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td valign="top">%q</td>
|
||||
<td>The query string (prepended with a ? if a query string exists, otherwise an empty string).</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td valign="top">%r</td>
|
||||
<td>First line of request.</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td valign="top">%R</td>
|
||||
<td>The handler generating the response (if any).</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td valign="top">%s</td>
|
||||
<td>Response status.</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td valign="top">%{format}t</td>
|
||||
<td>
|
||||
The time, in the form given by an optional format, parameter (default format [18/Sep/2011:19:18:28 -0400] where
|
||||
the last number indicates the timezone offset from GMT.)
|
||||
<br>
|
||||
The format parameter should be in a format supported by {@link DateCache}
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td valign="top">%T</td>
|
||||
<td>The time taken to serve the request, in seconds.</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td valign="top">%{UNIT}T</td>
|
||||
<td>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.</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td valign="top">%{d}u</td>
|
||||
<td>
|
||||
Remote user if the request was authenticated. May be bogus if return status (%s) is 401 (unauthorized).
|
||||
Optional parameter d, with this parameter deferred authentication will also be checked.
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td valign="top">%U</td>
|
||||
<td>The URL path requested, not including any query string.</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td valign="top">%X</td>
|
||||
<td>
|
||||
Connection status when response is completed:
|
||||
<pre>
|
||||
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.</pre>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td valign="top">%I</td>
|
||||
<td>Bytes received.</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td valign="top">%O</td>
|
||||
<td>Bytes sent.</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td valign="top">%S</td>
|
||||
<td>Bytes transferred (received and sent). This is the combination of %I and %O.</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td valign="top">%{VARNAME}^ti</td>
|
||||
<td>The contents of VARNAME: trailer line(s) in the request sent to the server.</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>%{VARNAME}^to</td>
|
||||
<td>The contents of VARNAME: trailer line(s) in the response sent from the server.</td>
|
||||
</tr>
|
||||
</table>
|
||||
* 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.
|
||||
* <p>
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
* <br><br>Percent codes are specified in the format %MODIFIERS{PARAM}CODE
|
||||
*<pre>
|
||||
* 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 {@link CustomRequestLog} table of format codes.
|
||||
* </pre>
|
||||
*
|
||||
* <table>
|
||||
* <caption>Format Codes</caption>
|
||||
* <tr>
|
||||
* <td><b>Format String</b></td>
|
||||
* <td><b>Description</b></td>
|
||||
* </tr>
|
||||
*
|
||||
* <tr>
|
||||
* <td>%%</td>
|
||||
* <td>The percent sign.</td>
|
||||
* </tr>
|
||||
*
|
||||
* <tr>
|
||||
* <td valign="top">%{format}a</td>
|
||||
* <td>
|
||||
* Address or Hostname. Valid formats are {server, client, local, remote}
|
||||
* Optional format parameter which will be server by default.
|
||||
* <br>
|
||||
* 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.
|
||||
* </td>
|
||||
* </tr>
|
||||
*
|
||||
* <tr>
|
||||
* <td valign="top">%{format}p</td>
|
||||
* <td>
|
||||
* Port. Valid formats are {server, client, local, remote}
|
||||
* Optional format parameter which will be server by default.
|
||||
* <br>
|
||||
* 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.
|
||||
* </td>
|
||||
* </tr>
|
||||
*
|
||||
* <tr>
|
||||
* <td valign="top">%{clf}I</td>
|
||||
* <td>
|
||||
* 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.
|
||||
* </td>
|
||||
* </tr>
|
||||
*
|
||||
* <tr>
|
||||
* <td valign="top">%{clf}O</td>
|
||||
* <td>
|
||||
* 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.
|
||||
* </td>
|
||||
* </tr>
|
||||
*
|
||||
* <tr>
|
||||
* <td valign="top">%{clf}S</td>
|
||||
* <td>
|
||||
* 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.
|
||||
* </td>
|
||||
* </tr>
|
||||
*
|
||||
* <tr>
|
||||
* <td valign="top">%{VARNAME}C</td>
|
||||
* <td>
|
||||
* 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.
|
||||
* </td>
|
||||
* </tr>
|
||||
*
|
||||
* <tr>
|
||||
* <td valign="top">%D</td>
|
||||
* <td>The time taken to serve the request, in microseconds.</td>
|
||||
* </tr>
|
||||
*
|
||||
* <tr>
|
||||
* <td valign="top">%{VARNAME}e</td>
|
||||
* <td>The contents of the environment variable VARNAME.</td>
|
||||
* </tr>
|
||||
*
|
||||
* <tr>
|
||||
* <td valign="top">%f</td>
|
||||
* <td>Filename.</td>
|
||||
* </tr>
|
||||
*
|
||||
* <tr>
|
||||
* <td valign="top">%H</td>
|
||||
* <td>The request protocol.</td>
|
||||
* </tr>
|
||||
*
|
||||
* <tr>
|
||||
* <td valign="top">%{VARNAME}i</td>
|
||||
* <td>The contents of VARNAME: header line(s) in the request sent to the server.</td>
|
||||
* </tr>
|
||||
*
|
||||
* <tr>
|
||||
* <td valign="top">%k</td>
|
||||
* <td>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).</td>
|
||||
* </tr>
|
||||
*
|
||||
* <tr>
|
||||
* <td valign="top">%m</td>
|
||||
* <td>The request method.</td>
|
||||
* </tr>
|
||||
*
|
||||
* <tr>
|
||||
* <td valign="top">%{VARNAME}o</td>
|
||||
* <td>The contents of VARNAME: header line(s) in the response.</td>
|
||||
* </tr>
|
||||
*
|
||||
* <tr>
|
||||
* <td valign="top">%q</td>
|
||||
* <td>The query string (prepended with a ? if a query string exists, otherwise an empty string).</td>
|
||||
* </tr>
|
||||
*
|
||||
* <tr>
|
||||
* <td valign="top">%r</td>
|
||||
* <td>First line of request.</td>
|
||||
* </tr>
|
||||
*
|
||||
* <tr>
|
||||
* <td valign="top">%R</td>
|
||||
* <td>The handler generating the response (if any).</td>
|
||||
* </tr>
|
||||
*
|
||||
* <tr>
|
||||
* <td valign="top">%s</td>
|
||||
* <td>Response status.</td>
|
||||
* </tr>
|
||||
*
|
||||
* <tr>
|
||||
* <td valign="top">%{format}t</td>
|
||||
* <td>
|
||||
* The time, in the form given by an optional format, parameter (default format [18/Sep/2011:19:18:28 -0400] where
|
||||
* the last number indicates the timezone offset from GMT.)
|
||||
* <br>
|
||||
* The format parameter should be in a format supported by {@link DateCache}
|
||||
* </td>
|
||||
* </tr>
|
||||
*
|
||||
* <tr>
|
||||
* <td valign="top">%T</td>
|
||||
* <td>The time taken to serve the request, in seconds.</td>
|
||||
* </tr>
|
||||
*
|
||||
* <tr>
|
||||
* <td valign="top">%{UNIT}T</td>
|
||||
* <td>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.</td>
|
||||
* </tr>
|
||||
*
|
||||
* <tr>
|
||||
* <td valign="top">%{d}u</td>
|
||||
* <td>
|
||||
* Remote user if the request was authenticated. May be bogus if return status (%s) is 401 (unauthorized).
|
||||
* Optional parameter d, with this parameter deferred authentication will also be checked.
|
||||
* </td>
|
||||
* </tr>
|
||||
*
|
||||
* <tr>
|
||||
* <td valign="top">%U</td>
|
||||
* <td>The URL path requested, not including any query string.</td>
|
||||
* </tr>
|
||||
*
|
||||
* <tr>
|
||||
* <td valign="top">%X</td>
|
||||
* <td>
|
||||
* Connection status when response is completed:
|
||||
* <pre>
|
||||
* 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.</pre>
|
||||
* </td>
|
||||
* </tr>
|
||||
*
|
||||
* <tr>
|
||||
* <td valign="top">%{VARNAME}^ti</td>
|
||||
* <td>The contents of VARNAME: trailer line(s) in the request sent to the server.</td>
|
||||
* </tr>
|
||||
*
|
||||
* <tr>
|
||||
* <td>%{VARNAME}^to</td>
|
||||
* <td>The contents of VARNAME: trailer line(s) in the response sent from the server.</td>
|
||||
* </tr>
|
||||
* </table>
|
||||
*/
|
||||
@ManagedObject("Custom format request log")
|
||||
public class CustomRequestLog extends ContainerLifeCycle implements RequestLog
|
||||
{
|
||||
protected static final Logger LOG = Log.getLogger(CustomRequestLog.class);
|
||||
|
||||
public static final String NCSA_FORMAT = "%a - %u %t \"%r\" %s %B \"%{Referer}i\" \"%{User-Agent}i\" \"%C\"";
|
||||
public static final String DEFAULT_DATE_FORMAT = "dd/MMM/yyyy:HH:mm:ss ZZZ";
|
||||
|
||||
public static final String NCSA_FORMAT = "%{client}a - %u %t \"%r\" %s %O";
|
||||
public static final String EXTENDED_NCSA_FORMAT = "%{client}a - %u %t \"%r\" %s %O \"%{Referer}i\" \"%{User-Agent}i\"";
|
||||
|
||||
private static ThreadLocal<StringBuilder> _buffers = ThreadLocal.withInitial(() -> new StringBuilder(256));
|
||||
|
||||
private String[] _ignorePaths;
|
||||
|
@ -286,9 +274,11 @@ public class CustomRequestLog extends ContainerLifeCycle implements RequestLog
|
|||
|
||||
private RequestLog.Writer _requestLogWriter;
|
||||
private final MethodHandle _logHandle;
|
||||
private final String _formatString;
|
||||
|
||||
public CustomRequestLog(RequestLog.Writer writer, String formatString)
|
||||
{
|
||||
_formatString = formatString;
|
||||
_requestLogWriter = writer;
|
||||
addBean(_requestLogWriter);
|
||||
|
||||
|
@ -335,6 +325,7 @@ public class CustomRequestLog extends ContainerLifeCycle implements RequestLog
|
|||
|
||||
/**
|
||||
* Extract the user authentication
|
||||
*
|
||||
* @param request The request to extract from
|
||||
* @param checkDeferred Whether to check for deferred authentication
|
||||
* @return The string to log for authenticated user.
|
||||
|
@ -378,6 +369,18 @@ public class CustomRequestLog extends ContainerLifeCycle implements RequestLog
|
|||
return _ignorePaths;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve the format string.
|
||||
*
|
||||
* @return the format string
|
||||
*/
|
||||
@ManagedAttribute("format string")
|
||||
public String getFormatString()
|
||||
{
|
||||
return _formatString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up request logging and open log file.
|
||||
*
|
||||
|
@ -474,6 +477,16 @@ public class CustomRequestLog extends ContainerLifeCycle implements RequestLog
|
|||
|
||||
private static List<Token> getTokens(String formatString)
|
||||
{
|
||||
/*
|
||||
Extracts literal strings and percent codes out of the format string.
|
||||
We will either match a percent code of the format %MODIFIERS{PARAM}CODE, or a literal string
|
||||
until the next percent code or the end of the formatString is reached.
|
||||
|
||||
where
|
||||
MODIFIERS is an optional comma separated list of numbers.
|
||||
{PARAM} is an optional string parameter to the percent code.
|
||||
CODE is a 1 to 2 character string corresponding to a format code.
|
||||
*/
|
||||
final Pattern PATTERN = Pattern.compile("^(?:%(?<MOD>!?[0-9,]+)?(?:\\{(?<ARG>[^}]+)})?(?<CODE>(?:(?:ti)|(?:to)|[a-zA-Z%]))|(?<LITERAL>[^%]+))(?<REMAINING>.*)");
|
||||
|
||||
List<Token> tokens = new ArrayList<>();
|
||||
|
@ -542,6 +555,7 @@ public class CustomRequestLog extends ContainerLifeCycle implements RequestLog
|
|||
|
||||
this.literal = null;
|
||||
}
|
||||
|
||||
public Token(String literal)
|
||||
{
|
||||
this.code = null;
|
||||
|
@ -564,7 +578,6 @@ public class CustomRequestLog extends ContainerLifeCycle implements RequestLog
|
|||
}
|
||||
|
||||
|
||||
|
||||
private MethodHandle updateLogHandle(MethodHandle logHandle, MethodHandle append, String literal)
|
||||
{
|
||||
return foldArguments(logHandle, dropArguments(dropArguments(append.bindTo(literal), 1, Request.class), 2, Response.class));
|
||||
|
@ -602,6 +615,9 @@ public class CustomRequestLog extends ContainerLifeCycle implements RequestLog
|
|||
|
||||
case "a":
|
||||
{
|
||||
if (arg == null || arg.isEmpty())
|
||||
arg = "server";
|
||||
|
||||
String method;
|
||||
switch (arg)
|
||||
{
|
||||
|
@ -629,23 +645,35 @@ public class CustomRequestLog extends ContainerLifeCycle implements RequestLog
|
|||
break;
|
||||
}
|
||||
|
||||
case "h":
|
||||
case "p":
|
||||
{
|
||||
String method = "logRemoteHostName";
|
||||
specificHandle = MethodHandles.lookup().findStatic(CustomRequestLog.class, method, logType);
|
||||
if (arg == null || arg.isEmpty())
|
||||
arg = "server";
|
||||
|
||||
String method;
|
||||
switch (arg)
|
||||
{
|
||||
|
||||
case "server":
|
||||
method = "logServerPort";
|
||||
break;
|
||||
|
||||
case "client":
|
||||
method = "logClientPort";
|
||||
break;
|
||||
|
||||
case "local":
|
||||
method = "logLocalPort";
|
||||
break;
|
||||
|
||||
case "remote":
|
||||
method = "logRemotePort";
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid arg for %p");
|
||||
}
|
||||
|
||||
case "B":
|
||||
{
|
||||
String method = "logResponseSize";
|
||||
specificHandle = MethodHandles.lookup().findStatic(CustomRequestLog.class, method, logType);
|
||||
break;
|
||||
}
|
||||
|
||||
case "b":
|
||||
{
|
||||
String method = "logResponseSizeCLF";
|
||||
specificHandle = MethodHandles.lookup().findStatic(CustomRequestLog.class, method, logType);
|
||||
break;
|
||||
}
|
||||
|
@ -656,9 +684,7 @@ public class CustomRequestLog extends ContainerLifeCycle implements RequestLog
|
|||
if (arg == null || arg.isEmpty())
|
||||
method = "logBytesReceived";
|
||||
else if (arg.equals("CLF"))
|
||||
{
|
||||
method = "logBytesReceivedCLF";
|
||||
}
|
||||
else
|
||||
throw new IllegalArgumentException("Invalid argument for %I");
|
||||
|
||||
|
@ -672,11 +698,23 @@ public class CustomRequestLog extends ContainerLifeCycle implements RequestLog
|
|||
if (arg == null || arg.isEmpty())
|
||||
method = "logBytesSent";
|
||||
else if (arg.equals("CLF"))
|
||||
{
|
||||
method = "logBytesSentCLF";
|
||||
}
|
||||
else
|
||||
throw new IllegalArgumentException("Invalid argument for %I");
|
||||
throw new IllegalArgumentException("Invalid argument for %O");
|
||||
|
||||
specificHandle = MethodHandles.lookup().findStatic(CustomRequestLog.class, method, logType);
|
||||
break;
|
||||
}
|
||||
|
||||
case "S":
|
||||
{
|
||||
String method;
|
||||
if (arg == null || arg.isEmpty())
|
||||
method = "logBytesTransferred";
|
||||
else if (arg.equals("CLF"))
|
||||
method = "logBytesTransferredCLF";
|
||||
else
|
||||
throw new IllegalArgumentException("Invalid argument for %S");
|
||||
|
||||
specificHandle = MethodHandles.lookup().findStatic(CustomRequestLog.class, method, logType);
|
||||
break;
|
||||
|
@ -767,36 +805,6 @@ public class CustomRequestLog extends ContainerLifeCycle implements RequestLog
|
|||
break;
|
||||
}
|
||||
|
||||
case "p":
|
||||
{
|
||||
String method;
|
||||
switch (arg)
|
||||
{
|
||||
|
||||
case "server":
|
||||
method = "logServerPort";
|
||||
break;
|
||||
|
||||
case "client":
|
||||
method = "logClientPort";
|
||||
break;
|
||||
|
||||
case "local":
|
||||
method = "logLocalPort";
|
||||
break;
|
||||
|
||||
case "remote":
|
||||
method = "logRemotePort";
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid arg for %p");
|
||||
}
|
||||
|
||||
specificHandle = MethodHandles.lookup().findStatic(CustomRequestLog.class, method, logType);
|
||||
break;
|
||||
}
|
||||
|
||||
case "q":
|
||||
{
|
||||
String method = "logQueryString";
|
||||
|
@ -891,14 +899,6 @@ public class CustomRequestLog extends ContainerLifeCycle implements RequestLog
|
|||
break;
|
||||
}
|
||||
|
||||
case "S":
|
||||
{
|
||||
String method = "logBytesTransferred";
|
||||
specificHandle = MethodHandles.lookup().findStatic(CustomRequestLog.class, method, logType);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
case "ti":
|
||||
{
|
||||
if (arg == null || arg.isEmpty())
|
||||
|
@ -940,7 +940,6 @@ public class CustomRequestLog extends ContainerLifeCycle implements RequestLog
|
|||
}
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------------//
|
||||
|
||||
private static void logNothing(StringBuilder b, Request request, Response response)
|
||||
|
@ -1007,17 +1006,47 @@ public class CustomRequestLog extends ContainerLifeCycle implements RequestLog
|
|||
b.append(response.getHttpChannel().getBytesWritten());
|
||||
}
|
||||
|
||||
private static void logBytesSentCLF(StringBuilder b, Request request, Response response)
|
||||
{
|
||||
long sent = response.getHttpChannel().getBytesWritten();
|
||||
if (sent == 0)
|
||||
b.append('-');
|
||||
else
|
||||
b.append(sent);
|
||||
}
|
||||
|
||||
private static void logBytesReceived(StringBuilder b, Request request, Response response)
|
||||
{
|
||||
//todo this be content received rather than consumed
|
||||
b.append(request.getHttpInput().getContentConsumed());
|
||||
}
|
||||
|
||||
private static void logBytesReceivedCLF(StringBuilder b, Request request, Response response)
|
||||
{
|
||||
//todo this be content received rather than consumed
|
||||
long received = request.getHttpInput().getContentConsumed();
|
||||
if (received == 0)
|
||||
b.append('-');
|
||||
else
|
||||
b.append(received);
|
||||
}
|
||||
|
||||
private static void logBytesTransferred(StringBuilder b, Request request, Response response)
|
||||
{
|
||||
//todo this be content received rather than consumed
|
||||
b.append(request.getHttpInput().getContentConsumed() + response.getHttpOutput().getWritten());
|
||||
}
|
||||
|
||||
private static void logBytesTransferredCLF(StringBuilder b, Request request, Response response)
|
||||
{
|
||||
//todo this be content received rather than consumed
|
||||
long transferred = request.getHttpInput().getContentConsumed() + response.getHttpOutput().getWritten();
|
||||
if (transferred == 0)
|
||||
b.append('-');
|
||||
else
|
||||
b.append(transferred);
|
||||
}
|
||||
|
||||
|
||||
private static void logRequestCookie(String arg, StringBuilder b, Request request, Response response)
|
||||
{
|
||||
|
|
|
@ -32,7 +32,8 @@ import org.eclipse.jetty.util.annotation.ManagedObject;
|
|||
* Format (single log format). This log format can be output by most web
|
||||
* servers, and almost all web log analysis software can understand these
|
||||
* formats.
|
||||
* @deprecated use {@link CustomRequestLog} given format string {@link CustomRequestLog#NCSA_FORMAT} with a {@link RequestLogWriter}
|
||||
*
|
||||
* @deprecated use {@link CustomRequestLog} given format string {@link CustomRequestLog#EXTENDED_NCSA_FORMAT} with a {@link RequestLogWriter}
|
||||
*/
|
||||
@Deprecated
|
||||
@ManagedObject("NCSA standard format request log")
|
||||
|
@ -40,7 +41,6 @@ public class NCSARequestLog extends AbstractNCSARequestLog
|
|||
{
|
||||
private final RequestLogWriter _requestLogWriter;
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Create request log object with default settings.
|
||||
*/
|
||||
|
@ -49,7 +49,6 @@ public class NCSARequestLog extends AbstractNCSARequestLog
|
|||
this((String)null);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Create request log object with specified output file name.
|
||||
*
|
||||
|
@ -62,7 +61,6 @@ public class NCSARequestLog extends AbstractNCSARequestLog
|
|||
this(new RequestLogWriter(filename));
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Create request log object given a RequestLogWriter file name.
|
||||
*
|
||||
|
@ -76,21 +74,18 @@ public class NCSARequestLog extends AbstractNCSARequestLog
|
|||
setExtended(true);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Set the output file name of the request log.
|
||||
* The file name may be in the format expected by
|
||||
* {@link RolloverFileOutputStream}.
|
||||
*
|
||||
* @param filename file name of the request log
|
||||
*
|
||||
*/
|
||||
public void setFilename(String filename)
|
||||
{
|
||||
_requestLogWriter.setFilename(filename);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public void setLogTimeZone(String tz)
|
||||
{
|
||||
|
@ -98,7 +93,6 @@ public class NCSARequestLog extends AbstractNCSARequestLog
|
|||
_requestLogWriter.setTimeZone(tz);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Retrieve the output file name of the request log.
|
||||
*
|
||||
|
@ -110,7 +104,6 @@ public class NCSARequestLog extends AbstractNCSARequestLog
|
|||
return _requestLogWriter.getFileName();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Retrieve the file name of the request log with the expanded
|
||||
* date wildcard if the output is written to the disk using
|
||||
|
@ -123,14 +116,12 @@ public class NCSARequestLog extends AbstractNCSARequestLog
|
|||
return _requestLogWriter.getDatedFilename();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
protected boolean isEnabled()
|
||||
{
|
||||
return _requestLogWriter.isEnabled();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Set the number of days before rotated log files are deleted.
|
||||
*
|
||||
|
@ -141,7 +132,6 @@ public class NCSARequestLog extends AbstractNCSARequestLog
|
|||
_requestLogWriter.setRetainDays(retainDays);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Retrieve the number of days before rotated log files are deleted.
|
||||
*
|
||||
|
@ -153,7 +143,6 @@ public class NCSARequestLog extends AbstractNCSARequestLog
|
|||
return _requestLogWriter.getRetainDays();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Set append to log flag.
|
||||
*
|
||||
|
@ -165,7 +154,6 @@ public class NCSARequestLog extends AbstractNCSARequestLog
|
|||
_requestLogWriter.setAppend(append);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Retrieve append to log flag.
|
||||
*
|
||||
|
@ -177,19 +165,17 @@ public class NCSARequestLog extends AbstractNCSARequestLog
|
|||
return _requestLogWriter.isAppend();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Set the log file name date format.
|
||||
* @see RolloverFileOutputStream#RolloverFileOutputStream(String, boolean, int, TimeZone, String, String)
|
||||
*
|
||||
* @param logFileDateFormat format string that is passed to {@link RolloverFileOutputStream}
|
||||
* @see RolloverFileOutputStream#RolloverFileOutputStream(String, boolean, int, TimeZone, String, String)
|
||||
*/
|
||||
public void setFilenameDateFormat(String logFileDateFormat)
|
||||
{
|
||||
_requestLogWriter.setFilenameDateFormat(logFileDateFormat);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Retrieve the file name date format string.
|
||||
*
|
||||
|
@ -200,14 +186,12 @@ public class NCSARequestLog extends AbstractNCSARequestLog
|
|||
return _requestLogWriter.getFilenameDateFormat();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public void write(String requestEntry) throws IOException
|
||||
{
|
||||
_requestLogWriter.write(requestEntry);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Set up request logging and open log file.
|
||||
*
|
||||
|
@ -219,7 +203,6 @@ public class NCSARequestLog extends AbstractNCSARequestLog
|
|||
super.doStart();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Close the log file and perform cleanup.
|
||||
*
|
||||
|
|
|
@ -25,6 +25,7 @@ import org.eclipse.jetty.server.handler.RequestLogHandler;
|
|||
/**
|
||||
* A <code>RequestLog</code> can be attached to a {@link org.eclipse.jetty.server.handler.RequestLogHandler} to enable
|
||||
* logging of requests/responses.
|
||||
*
|
||||
* @see RequestLogHandler#setRequestLog(RequestLog)
|
||||
* @see Server#setRequestLog(RequestLog)
|
||||
*/
|
||||
|
@ -40,6 +41,9 @@ public interface RequestLog
|
|||
*/
|
||||
void log(Request request, Response response);
|
||||
|
||||
/**
|
||||
* Writes the generated log string to a log sink
|
||||
*/
|
||||
interface Writer
|
||||
{
|
||||
void write(String requestEntry) throws IOException;
|
||||
|
|
|
@ -29,6 +29,9 @@ import org.eclipse.jetty.util.component.AbstractLifeCycle;
|
|||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
|
||||
/**
|
||||
* Writer which outputs pre-formatted request log strings to a file using {@link RolloverFileOutputStream}.
|
||||
*/
|
||||
public class RequestLogWriter extends AbstractLifeCycle implements RequestLog.Writer
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(RequestLogWriter.class);
|
||||
|
@ -63,7 +66,6 @@ public class RequestLogWriter extends AbstractLifeCycle implements RequestLog.Wr
|
|||
* {@link RolloverFileOutputStream}.
|
||||
*
|
||||
* @param filename file name of the request log
|
||||
*
|
||||
*/
|
||||
public void setFilename(String filename)
|
||||
{
|
||||
|
@ -86,7 +88,6 @@ public class RequestLogWriter extends AbstractLifeCycle implements RequestLog.Wr
|
|||
return _filename;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve the file name of the request log with the expanded
|
||||
* date wildcard if the output is written to the disk using
|
||||
|
@ -126,7 +127,6 @@ public class RequestLogWriter extends AbstractLifeCycle implements RequestLog.Wr
|
|||
return _retainDays;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set append to log flag.
|
||||
*
|
||||
|
@ -148,19 +148,17 @@ public class RequestLogWriter extends AbstractLifeCycle implements RequestLog.Wr
|
|||
return _append;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the log file name date format.
|
||||
* @see RolloverFileOutputStream#RolloverFileOutputStream(String, boolean, int, TimeZone, String, String)
|
||||
*
|
||||
* @param logFileDateFormat format string that is passed to {@link RolloverFileOutputStream}
|
||||
* @see RolloverFileOutputStream#RolloverFileOutputStream(String, boolean, int, TimeZone, String, String)
|
||||
*/
|
||||
public void setFilenameDateFormat(String logFileDateFormat)
|
||||
{
|
||||
_filenameDateFormat = logFileDateFormat;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Retrieve the file name date format string.
|
||||
*
|
||||
|
@ -171,7 +169,6 @@ public class RequestLogWriter extends AbstractLifeCycle implements RequestLog.Wr
|
|||
return _filenameDateFormat;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public void write(String requestEntry) throws IOException
|
||||
{
|
||||
|
@ -185,12 +182,6 @@ public class RequestLogWriter extends AbstractLifeCycle implements RequestLog.Wr
|
|||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Set up request logging and open log file.
|
||||
*
|
||||
* @see org.eclipse.jetty.util.component.AbstractLifeCycle#doStart()
|
||||
*/
|
||||
@Override
|
||||
protected synchronized void doStart() throws Exception
|
||||
{
|
||||
|
@ -222,12 +213,6 @@ public class RequestLogWriter extends AbstractLifeCycle implements RequestLog.Wr
|
|||
return _timeZone;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Close the log file and perform cleanup.
|
||||
*
|
||||
* @see org.eclipse.jetty.util.component.AbstractLifeCycle#doStop()
|
||||
*/
|
||||
@Override
|
||||
protected void doStop() throws Exception
|
||||
{
|
||||
|
|
|
@ -24,7 +24,7 @@ import org.eclipse.jetty.util.annotation.ManagedObject;
|
|||
|
||||
/**
|
||||
* Implementation of NCSARequestLog where output is sent as a SLF4J INFO Log message on the named logger "org.eclipse.jetty.server.RequestLog"
|
||||
* @deprecated use {@link CustomRequestLog} given format string {@link CustomRequestLog#NCSA_FORMAT} with an {@link Slf4jRequestLogWriter}
|
||||
* @deprecated use {@link CustomRequestLog} given format string {@link CustomRequestLog#EXTENDED_NCSA_FORMAT} with an {@link Slf4jRequestLogWriter}
|
||||
*/
|
||||
@Deprecated
|
||||
@ManagedObject("NCSA standard format request log to slf4j bridge")
|
||||
|
|
Loading…
Reference in New Issue