| <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 11. Jetty Logging"><link rel="prev" href="default-logging-with-stderrlog.html" title="Default Logging with Jetty’s StdErrLog"><link rel="next" href="configuring-logging-modules.html" title="Jetty Logging Integrations (SLF4J, Log4j, Logback, JCL, JUL)"><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.4.28-SNAPSHOT</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> </td><th width="60%" align="center">Chapter 11. 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"> <a accesskey="n" href="configuring-logging-modules.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#request-log-custom-writer">Introducing RequestLog.Writer</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’s <a class="link" href="http://www.eclipse.org/jetty/javadoc/9.4.28-SNAPSHOT/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-start=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 <a class="link" href="startup-modules.html#start-vs-startd" title="Start.ini vs. Start.d"><code class="literal">{$jetty.base}/start.d</code> directory</a>.</p><div class="blockquote"><blockquote class="blockquote"><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="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title"><i class="fa fa-asterisk" aria-hidden="true"></i> Note</h3><p>By default, request logs are not set to be appended, meaning a the log file is wiped clean upon sever restart. |
| You can change this setting by editing the <code class="literal">requestlog.ini</code> and un-commenting the line that reads <code class="literal">jetty.requestlog.append=true</code>.</p></div></blockquote></div><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></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="request-log-custom-writer"></a>Introducing RequestLog.Writer</h3></div></div></div><p>The concept of a <code class="literal">RequestLog.Writer</code>, introduced in Jetty 9.4.15, manages the writing to a log the string generated by the <code class="literal">RequestLog</code>. |
| This allows the <code class="literal">CustomRequestLog</code> to match the functionality of other <code class="literal">RequestLogger</code> implementations by plugging in any <code class="literal">RequestLog.Writer</code> and a custom format string. |
| Jetty currently has implementations of <code class="literal">RequestLog.Writer</code>, <code class="literal">RequestLogWriter</code>, <code class="literal">AsyncRequestLogWriter</code>, and <code class="literal">Slf4jRequestLogWriter</code>.</p><p>So, the way to create an asynchronous <code class="literal">RequestLog</code> using the extended NCSA format has been changed from:</p><p><code class="literal">new AsyncNcsaRequestLog(filename)</code></p><p>to:</p><p><code class="literal">new CustomRequestLog(new AsyncRequestLogWriter(filename), CustomRequestLog.EXTENDED_NCSA_FORMAT)</code></p><p>Additionally, there are now two settings for the log timezone to be configured. |
| There is the configuration for logging the request time, which is set in the <code class="literal">timeZone</code> parameter in the <code class="literal">%t</code> format code of the string, given in the format <code class="literal">%{format|timeZone|locale}t</code>.</p><p>The other <code class="literal">timeZone</code> parameter relates to the generation of the log file name (both at creation and roll over). |
| This is configured in the <code class="literal">requestlog</code> module file, or can be used as a setter on <code class="literal">RequestLogWriter</code> via XML.</p><p>Both timezones are set to GMT by default.</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><Configure class="org.eclipse.jetty.webapp.WebAppContext"> |
| ... |
| <Call name="insertHandler"> |
| <Arg> |
| <New id="RequestLog" class="org.eclipse.jetty.server.handler.RequestLogHandler"> |
| <Set name="requestLog"> |
| <New id="RequestLogImpl" class="org.eclipse.jetty.server.NCSARequestLog"> |
| <Set name="filename"><Property name="jetty.logs" default="./logs"/>/test-yyyy_mm_dd.request.log</Set> |
| <Set name="filenameDateFormat">yyyy_MM_dd</Set> |
| <Set name="LogTimeZone">GMT</Set> |
| <Set name="retainDays">90</Set> |
| <Set name="append">true</Set> |
| <Set name="LogLatency">true</Set> |
| </New> |
| </Set> |
| </New> |
| </Arg> |
| </Call> |
| ... |
| </Configure></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> </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"> <a accesskey="n" href="configuring-logging-modules.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’s StdErrLog </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"> Jetty Logging Integrations (SLF4J, Log4j, Logback, JCL, JUL)</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: 2020-03-10)</i></span></div></p></body></html> |