Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "Jetty/Howto/Configure Request Logs"
(New page: {{Jetty Howto | introduction = 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 [http://hoohoo...) |
m |
||
Line 1: | Line 1: | ||
− | + | {Jetty Howto | |
| introduction = 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 [http://hoohoo.ncsa.uiuc.edu/docs/setup/httpd/LogOptions.html NCSA format], so you can conveniently analyze these logs using tools such as [http://www.mrunix.net/webalizer/ webalizer]. | | introduction = 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 [http://hoohoo.ncsa.uiuc.edu/docs/setup/httpd/LogOptions.html NCSA format], so you can conveniently analyze these logs using tools such as [http://www.mrunix.net/webalizer/ webalizer]. | ||
Line 25: | Line 25: | ||
<div class="code panel" style="border-width: 1px"><div class="codeContent panelContent"> | <div class="code panel" style="border-width: 1px"><div class="codeContent panelContent"> | ||
− | + | <Set name="handler"> | |
− | + | <New id="Handlers" class="org.mortbay.jetty.handler.HandlerCollection"> | |
− | + | <Set name="handlers"> | |
− | + | <Array type="org.mortbay.jetty.Handler"> | |
− | + | <Item> | |
− | + | <New id="Contexts" class="org.mortbay.jetty.handler.ContextHandlerCollection"/> | |
− | + | </Item> | |
− | + | <Item> | |
− | + | <New id="DefaultHandler" class="org.mortbay.jetty.handler.DefaultHandler"/> | |
− | + | </Item> | |
− | + | <Item> | |
− | + | <New id="RequestLog" class="org.mortbay.jetty.handler.RequestLogHandler"/> | |
− | + | </Item> | |
− | + | </Array> | |
− | + | </Set> | |
− | + | </New> | |
− | + | </Set> | |
− | + | <Ref id="RequestLog"> | |
− | + | <Set name="requestLog"> | |
− | + | <New id="RequestLogImpl" class="org.mortbay.jetty.NCSARequestLog"> | |
− | + | <Arg><SystemProperty name="jetty.logs" default="./logs"/>/yyyy_mm_dd.request.log</Arg> | |
− | + | <Set name="retainDays">90</Set> | |
− | + | <Set name="append">true</Set> | |
− | + | <Set name="extended">false</Set> | |
− | + | <Set name="LogTimeZone">GMT</Set> | |
− | + | </New> | |
− | + | </Set> | |
− | + | </Ref> | |
</div></div> | </div></div> | ||
Line 62: | Line 62: | ||
<div class="code panel" style="border-width: 1px"><div class="codeContent panelContent"> | <div class="code panel" style="border-width: 1px"><div class="codeContent panelContent"> | ||
− | HandlerCollection handlers = | + | HandlerCollection handlers = new HandlerCollection(); |
− | ContextHandlerCollection contexts = | + | ContextHandlerCollection contexts = new ContextHandlerCollection(); |
− | RequestLogHandler requestLogHandler = | + | RequestLogHandler requestLogHandler = new RequestLogHandler(); |
− | handlers.setHandlers( | + | handlers.setHandlers(new Handler[]{contexts,new DefaultHandler(),requestLogHandler}); |
server.setHandler(handlers); | server.setHandler(handlers); | ||
− | NCSARequestLog requestLog = | + | NCSARequestLog requestLog = new NCSARequestLog("./logs/jetty-yyyy_mm_dd.request.log"); |
requestLog.setRetainDays(90); | requestLog.setRetainDays(90); | ||
− | requestLog.setAppend( | + | requestLog.setAppend(true); |
− | requestLog.setExtended( | + | requestLog.setExtended(false); |
− | requestLog.setLogTimeZone( | + | requestLog.setLogTimeZone("GMT"); |
requestLogHandler.setRequestLog(requestLog); | requestLogHandler.setRequestLog(requestLog); | ||
Line 85: | Line 85: | ||
<div class="code panel" style="border-width: 1px"><div class="codeContent panelContent"> | <div class="code panel" style="border-width: 1px"><div class="codeContent panelContent"> | ||
− | + | <Configure class="org.mortbay.jetty.webapp.WebAppContext"> | |
... | ... | ||
− | + | <Call name="addHandler"> | |
− | + | <Arg> | |
− | + | <New class="org.mortbay.jetty.handler.RequestLogHandler"> | |
− | + | <Set name="requestLog"> | |
− | + | <New id="RequestLogImpl" class="org.mortbay.jetty.NCSARequestLog"> | |
− | + | <Arg><SystemProperty name="jetty.logs" default="./logs"/>/yyyy_mm_dd.test.request.log</Arg> | |
− | + | <Set name="retainDays">90</Set> | |
− | + | <Set name="append">true</Set> | |
− | + | <Set name="extended">false</Set> | |
− | + | <Set name="LogTimeZone">GMT</Set> | |
− | + | </New> | |
− | + | </Set> | |
− | + | </New> | |
− | + | </Arg> | |
− | + | </Call> | |
... | ... | ||
− | + | </Configure> | |
</div> | </div> |
Revision as of 14:37, 26 August 2010
{Jetty Howto | introduction = 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 conveniently analyze these logs using tools such as webalizer.
A standard request log entry includes the client IP address, date, method, URL, result, size, referrer and user agent, for example:
123.4.5.6 - - [27/Aug/2004: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"
Jetty provides an implementation called NCSARequestLog which supports the NCSA format in files that can be rolled over on a daily basis.
The logback project offers another implementation of RequestLog interface providing very rich and powerful HTTP-access log functionality,
If neither of these options suits you, you can implement a custom request logger by implementing Jetty's RequestLog.java interface and plugging it in in similar fashion to the NCSARequestLog, as shown below.
Configuring a Request Log for a Jetty Server
To configure a single request log for the entire Jetty Server instance:
<Set name="handler">
<New id="Handlers" class="org.mortbay.jetty.handler.HandlerCollection">
<Set name="handlers">
<Array type="org.mortbay.jetty.Handler">
<Item>
<New id="Contexts" class="org.mortbay.jetty.handler.ContextHandlerCollection"/>
</Item>
<Item>
<New id="DefaultHandler" class="org.mortbay.jetty.handler.DefaultHandler"/>
</Item>
<Item>
<New id="RequestLog" class="org.mortbay.jetty.handler.RequestLogHandler"/>
</Item>
</Array>
</Set>
</New>
</Set>
Cite error: Invalid <ref>
tag;
invalid names, e.g. too many
The equivalent code is:
HandlerCollection handlers = new HandlerCollection(); ContextHandlerCollection contexts = new ContextHandlerCollection(); RequestLogHandler requestLogHandler = new RequestLogHandler(); handlers.setHandlers(new Handler[]{contexts,new DefaultHandler(),requestLogHandler}); server.setHandler(handlers); NCSARequestLog requestLog = new NCSARequestLog("./logs/jetty-yyyy_mm_dd.request.log"); requestLog.setRetainDays(90); requestLog.setAppend(true); requestLog.setExtended(false); requestLog.setLogTimeZone("GMT"); requestLogHandler.setRequestLog(requestLog);
This configures a request log in $JETTY_HOME/logs with filenames including the date. Old log files are kept for 90 days before being deleted. Existing log files are appended to and the extended NCSA format is used in the GMT timezone.
There are many more configuration options available - see http://jetty.mortbay.org/apidocs/org/mortbay/jetty/NCSARequestLog.html
Configuring a Request Log per webapp
<Configure class="org.mortbay.jetty.webapp.WebAppContext"> ... <Call name="addHandler"> <Arg> <New class="org.mortbay.jetty.handler.RequestLogHandler"> <Set name="requestLog"> <New id="RequestLogImpl" class="org.mortbay.jetty.NCSARequestLog"> <Arg><SystemProperty name="jetty.logs" default="./logs"/>/yyyy_mm_dd.test.request.log</Arg> <Set name="retainDays">90</Set> <Set name="append">true</Set> <Set name="extended">false</Set> <Set name="LogTimeZone">GMT</Set> </New> </Set> </New> </Arg> </Call> ... </Configure>
| more = (optional) - links, additional references
}}