Reputation: 530
I'm using the xsbt-web-plugin
to develop a webservice.
For easier debugging I would like to switch on request logs in console like the line below.
[22/Dez/2012:15:29:56 +0000] "GET /messages HTTP/1.1" 200 27276
In production I'm using NCSARequestLog
which is fine, but in development I would like to include the log in my sbt console
where I started the container via container:start
/
How can I enable the request logs?
Upvotes: 2
Views: 785
Reputation: 13473
To enable request logs, you can configure an NCSARequestLog
via a custom jetty.xml file.
Add this to build.sbt:
env in Compile := Some(file(".") / "jetty-env.xml" asFile)
Create myproject/jetty-env.xml:
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="handler">
<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>
</New>
</Set>
</New>
</Set>
</Configure>
In sbt, run container:start
, and you'll see request logs collected under myproject/logs. When I tested this, Jetty would not create the logs directory on its own - I had to do that myself.
You can watch the request log in real time with tail
:
tail -f myproject/logs/test-2013_08_23.request.log
For a full example of this, see the request-logging branch of xwp-template.
Upvotes: 1