[英]Request log in console for Jetty container using xsbt-web-plugin
I'm using the xsbt-web-plugin
to develop a webservice. 我正在使用
xsbt-web-plugin
开发Web服务。
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
[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
/ 在生产中,我使用的是
NCSARequestLog
,这很好,但是在开发中,我希望将日志包含在sbt console
,在sbt console
,我通过container:start
/启动了容器
How can I enable the request logs? 如何启用请求日志?
To enable request logs, you can configure an NCSARequestLog
via a custom jetty.xml file. 要启用请求日志,您可以通过自定义jetty.xml文件配置
NCSARequestLog
。
Add this to build.sbt : 将其添加到build.sbt :
env in Compile := Some(file(".") / "jetty-env.xml" asFile)
Create myproject/jetty-env.xml : 创建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 . 在sbt中,运行
container:start
,您将看到在myproject / logs下收集的请求日志 。 When I tested this, Jetty would not create the logs directory on its own - I had to do that myself. 当我对此进行测试时,Jetty不会自己创建日志目录-我必须自己做。
You can watch the request log in real time with tail
: 您可以使用
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 . 有关此示例的完整示例,请参见xwp-template的request-logging分支 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.