blob: 9ab2335c9c8bd83f331cfd682ef3fc3c6fa525de [file] [log] [blame]
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Configuring Jetty Request Logs</title><link rel="stylesheet" type="text/css" href="css/docbook.css"><meta name="generator" content="DocBook XSL Stylesheets V1.79.1"><meta name="keywords" content="jetty, servlet, servlet-api, cometd, http, websocket, eclipse, maven, java, server, software"><link rel="home" href="index.html" title="Jetty"><link rel="up" href="configuring-logging.html" title="Chapter&nbsp;11.&nbsp;Jetty Logging"><link rel="prev" href="default-logging-with-stderrlog.html" title="Default Logging with Jetty&#8217;s StdErrLog"><link rel="next" href="example-logging-log4j.html" title="Example: Logging with Apache Log4j"><link xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" rel="shortcut icon" href="images/favicon.ico"><link rel="stylesheet" href="css/highlighter/foundation.css"><script src="js/highlight.pack.js"></script><script>
hljs.initHighlightingOnLoad();
</script><link type="text/css" rel="stylesheet" href="css/font-awesome/font-awesome.min.css"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><table xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times"><tr><td style="width: 25%"><a href="http://www.eclipse.org/jetty"><img src="images/jetty-header-logo.png" alt="Jetty Logo"></a><br><span style="font-size: small">
Version: 9.3.28.v20191105</span></td><td style="width: 50%"></td></tr></table><div xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Configuring Jetty Request Logs</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="default-logging-with-stderrlog.html"><i class="fa fa-chevron-left" aria-hidden="true"></i> Previous</a>&nbsp;</td><th width="60%" align="center">Chapter&nbsp;11.&nbsp;Jetty Logging<br><a accesskey="p" href="index.html"><i class="fa fa-home" aria-hidden="true"></i> Home</a></th><td width="20%" align="right">&nbsp;<a accesskey="n" href="example-logging-log4j.html">Next <i class="fa fa-chevron-right" aria-hidden="true"></i></a></td></tr></table><hr></div><div xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" class="jetty-callout"><h5 class="callout"><a href="http://www.webtide.com/">Contact the core Jetty developers at
<span class="website">www.webtide.com</span></a></h5><p>
private support for your internal/customer projects ... custom extensions and distributions ... versioned snapshots for indefinite support ...
scalability guidance for your apps and Ajax/Comet projects ... development services for sponsored feature development
</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="configuring-jetty-request-logs"></a>Configuring Jetty Request Logs</h2></div></div></div><div class="toc"><dl class="toc"><dt><span class="section"><a href="configuring-jetty-request-logs.html#constructing-request-log-entry">Constructing a Request Log Entry</a></span></dt><dt><span class="section"><a href="configuring-jetty-request-logs.html#implementing-request-log">Implementing a Request Log</a></span></dt><dt><span class="section"><a href="configuring-jetty-request-logs.html#configuring-request-log">Configuring the Request Log module</a></span></dt><dt><span class="section"><a href="configuring-jetty-request-logs.html#configuring-separate-request-log-for-web-application">Configuring a Separate Request Log For a Web Application</a></span></dt></dl></div><p>Request logs are a record of the requests that the server has processed.
There is one entry per request received, and commonly in the standard NCSA format, so you can use tools like <a class="link" href="http://en.wikipedia.org/wiki/Webalizer" target="_top">Webalizer</a> to analyze them conveniently.</p><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="constructing-request-log-entry"></a>Constructing a Request Log Entry</h3></div></div></div><p>A standard request log entry includes the client IP address, date, method, URL, result, size, referrer, user agent and latency.
For example:</p><pre class="literallayout">123.4.5.6 - - [20/Jul/2016:10:16:17 +0000]
"GET /jetty/tut/XmlConfiguration.html HTTP/1.1"
200 76793 "http://localhost:8080/jetty/tut/logging.html"
"Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040614 Firefox/0.8" 342</pre></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="implementing-request-log"></a>Implementing a Request Log</h3></div></div></div><p>Jetty provides an implementation called <code class="literal">NCSARequestLog</code> which supports the NCSA format in files that will roll over on a daily basis.</p><p>The <a class="link" href="http://logback.qos.ch/" target="_top">Logback Project</a> offers <a class="link" href="http://logback.qos.ch/access.html" target="_top">another implementation</a> of a <code class="literal">RequestLog</code> interface, providing rich and powerful HTTP-access log functionality.</p><p>If neither of these options meets your needs, you can implement a custom request logger by implementing Jetty&#8217;s <a class="link" href="http://www.eclipse.org/jetty/javadoc/9.3.28.v20191105/org/eclipse/jetty/server/RequestLog.html" target="_top"><code class="literal">RequestLog.java</code></a> interface and plugging it in similar to the <code class="literal">NCSARequestLog</code>, as shown below.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="configuring-request-log"></a>Configuring the Request Log module</h3></div></div></div><p>To enable the Request Log module for the entire server via the Jetty distribution, it first needs to be enabled on the command line:</p><div class="screenexample"><pre class="screen">$ java -jar ../start.jar --add-to-startd=requestlog
INFO: requestlog initialised in ${jetty.base}/start.d/requestlog.ini
MKDIR: ${jetty.base}/logs
INFO: Base directory was modified</pre></div><p>The above command will add a new <code class="literal">requestlog.ini</code> file to your <code class="literal">{$jetty.base}/start.d</code> directory.
If you used <code class="literal">--add-to-start</code> it will append the configuration options for the module to the <code class="literal">start.ini</code> file located in your <code class="literal">{$jetty.base}</code> directory.</p><p>The equivalent code for embedded usages of Jetty is:</p><pre xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times"><code>NCSARequestLog requestLog = new NCSARequestLog("/var/logs/jetty/jetty-yyyy_mm_dd.request.log");
requestLog.setAppend(true);
requestLog.setExtended(false);
requestLog.setLogTimeZone("GMT");
requestLog.setLogLatency(true);
requestLog.setRetainDays("90");
server.setRequestLog(requestLog);</code></pre><p>This configures a request log in <code class="literal">{$jetty.home}/logs</code> with filenames including the date.
Existing log files are appended to and the extended NCSA format is used in the GMT time zone.</p><p>The above configuration enables Log Latency, which is the amount of time it took the server to handle the request.
This value is measured in milliseconds and is appended to the the log file for each request.</p><p>You can also customize the number of days you wish to keep request logs.
By default, log files are kept for 90 days before being deleted.
The value for <code class="literal">retainDays</code> (xml) or <code class="literal">setRetainDays</code> (Java) should be configured as <span class="emphasis"><em>1 + n</em></span> days.
For example, if you wanted to keep the logs for the current day and the day prior you would set the <code class="literal">retainDays</code> (or <code class="literal">setRetainDays</code>) value to 2.</p><p>To examine more configuration options, see <a class="link" href="http://www.eclipse.org/jetty/javadoc/9.3.28.v20191105/org/eclipse/jetty/server/NCSARequestLog.html" target="_top">NCSARequestLog.java</a>.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="configuring-separate-request-log-for-web-application"></a>Configuring a Separate Request Log For a Web Application</h3></div></div></div><p>To configure a separate request log for specific a web application, add the following to the context XML file.</p><pre xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times"><code>&lt;Configure class="org.eclipse.jetty.webapp.WebAppContext"&gt;
...
&lt;Call name="insertHandler"&gt;
&lt;Arg&gt;
&lt;New id="RequestLog" class="org.eclipse.jetty.server.handler.RequestLogHandler"&gt;
&lt;Set name="requestLog"&gt;
&lt;New id="RequestLogImpl" class="org.eclipse.jetty.server.NCSARequestLog"&gt;
&lt;Set name="filename"&gt;&lt;Property name="jetty.logs" default="./logs"/&gt;/test-yyyy_mm_dd.request.log&lt;/Set&gt;
&lt;Set name="filenameDateFormat"&gt;yyyy_MM_dd&lt;/Set&gt;
&lt;Set name="LogTimeZone"&gt;GMT&lt;/Set&gt;
&lt;Set name="retainDays"&gt;90&lt;/Set&gt;
&lt;Set name="append"&gt;true&lt;/Set&gt;
&lt;Set name="LogLatency"&gt;true&lt;/Set&gt;
&lt;/New&gt;
&lt;/Set&gt;
&lt;/New&gt;
&lt;/Arg&gt;
&lt;/Call&gt;
...
&lt;/Configure&gt;</code></pre></div></div><script type="text/javascript">
SyntaxHighlighter.all()
</script><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="default-logging-with-stderrlog.html"><i class="fa fa-chevron-left" aria-hidden="true"></i> Previous</a>&nbsp;</td><td width="20%" align="center"><a accesskey="u" href="configuring-logging.html"><i class="fa fa-chevron-up" aria-hidden="true"></i> Top</a></td><td width="40%" align="right">&nbsp;<a accesskey="n" href="example-logging-log4j.html">Next <i class="fa fa-chevron-right" aria-hidden="true"></i></a></td></tr><tr><td width="40%" align="left" valign="top">Default Logging with Jetty&#8217;s StdErrLog&nbsp;</td><td width="20%" align="center"><a accesskey="h" href="index.html"><i class="fa fa-home" aria-hidden="true"></i> Home</a></td><td width="40%" align="right" valign="top">&nbsp;Example: Logging with Apache Log4j</td></tr></table></div><p xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times"><div class="jetty-callout">
See an error or something missing?
<span class="callout"><a href="http://github.com/eclipse/jetty.project">Contribute to this documentation at
<span class="website"><i class="fa fa-github" aria-hidden="true"></i> Github!</span></a></span><span style="float: right"><i>(Generated: 2019-11-05)</i></span></div></p></body></html>