java Jetty HTTP 日志记录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13735676/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Jetty HTTP logging
提问by Steve Kuo
I would like to have Jetty log all HTTP requests (along with the body) and responses. Is this natively supported by Jetty? Ideally it would log to my existing log4j log file.
我想让 Jetty 记录所有 HTTP 请求(连同正文)和响应。这是 Jetty 本身支持的吗?理想情况下,它会记录到我现有的 log4j 日志文件中。
I am running Jetty 6.
我正在运行 Jetty 6。
采纳答案by Thomas Becker
Jetty comes with a request logger that can log in NCSA format. That format doesn't include things like request body as you require, but that standard format will fit tools like webalizer and the like.
Jetty 带有一个请求记录器,可以以 NCSA 格式登录。该格式不包括您需要的请求正文之类的内容,但该标准格式将适合 webalizer 等工具。
If you need to log more you can use the logback request log implementation or write your own logger by implementing Jetty's RequestLog interface.
如果需要记录更多日志,可以使用 logback 请求日志实现或通过实现 Jetty 的 RequestLog 接口编写自己的记录器。
Besides that I'd highly recommend to upgrade to jetty7/8 (same codebase, but 8 provides servlet 3.0 functionality). Or directly move to jetty9.
除此之外,我强烈建议升级到 jetty7/8(相同的代码库,但 8 提供了 servlet 3.0 功能)。或者直接移动到jetty9。
Here's the jetty9 documentation for request logs: http://www.eclipse.org/jetty/documentation/current/configuring-logging.html#configuring-jetty-request-logs
这是请求日志的 jetty9 文档:http: //www.eclipse.org/jetty/documentation/current/configuring-logging.html#configuring-jetty-request-logs
Same for jetty7/8: http://wiki.eclipse.org/Jetty/Tutorial/RequestLog
jetty7/8 相同:http://wiki.eclipse.org/Jetty/Tutorial/RequestLog
I leave it as an exercise for you to find the jetty6 docs or better yet, upgrade. :)
我把它作为一个练习让你找到 jetty6 文档或者更好的是,升级。:)
Ok, just found the jetty6 docs by accident: http://docs.codehaus.org/display/JETTY/Logging+Requests
好吧,偶然发现了 jetty6 文档:http://docs.codehaus.org/display/JETTY/Logging+Requests
回答by freedev
TL;DR
TL; 博士
You have to enable the right modules, just add into the start.ini
file:
您必须启用正确的模块,只需添加到start.ini
文件中:
#?Create access log file
--module=requestlog
# Redirect all the console log to a file
--module=console-capture
Restart Jetty and have a look into the logs directory.
重新启动 Jetty 并查看日志目录。