简体   繁体   English

Tomcat请求记录-如何?

[英]Tomcat request logging - how to?

Env: Tomcat 7. 信封:Tomcat 7。

Would like to log http requests and their headers. 想要记录http请求及其标头。 Actually I could do without the headers as long as I can log the IP address of the caller, the resource he's requesting (the URL) and the type of request (GET, POST, etc) 实际上,只要我可以记录调用者的IP地址,他请求的资源(URL)和请求的类型(GET,POST等),我就可以没有标题。

This may seem like a trivial question, but it really isn't. 这似乎是一个琐碎的问题,但实际上并非如此。

The standard way would be to use the AccessLogValve , but as far as I understand that one is actually not request logging, it is request/response logging, meaning that it will not log anything before at the end of the response cycle. 标准方法是使用AccessLogValve ,但是据我所知,实际上不是请求日志记录,而是请求/响应日志记录,这意味着在响应周期结束之前它不会记录任何内容。 It will only log those requests where a response has successfully been delivered to the http client. 它将仅记录那些已成功将响应传递到http客户端的请求。 If something goes wrong before that AccessLogValve will not log the request. 如果在此之前出现问题,则AccessLogValve将不会记录请求。

Question 1: Is this correctly understood? 问题1:这是否正确理解?

Question 2: Are there other options? 问题2:还有其他选择吗?

UPDATE 1: 更新1:

I've done a test with Tomcat7 using a dummy-servlet that does blocking for x seconds based on an URL parameter. 我已经使用Tomcat-servlet对Tomcat7进行了测试,该servlet根据URL参数进行了x秒的阻塞。 My findings are that indeed that request gets logged by the AccessLogValve ... although as expected this does not happen until the end of the response, ie after the x seconds. 我的发现是,确实该请求已由AccessLogValve记录...尽管按预期,直到响应结束(即x秒之后),该请求才会发生。 There will be a log entry regardless if the client has aborted before the request finishes and regardless if the servlet throws an exception during processing. 无论客户端在请求完成之前是否已中止,以及servlet在处理期间是否引发异常,都将存在一个日志条目。

Therefore the answer to question 1 is : "No". 因此,问题1的答案是:“否”。

Conclusion 结论

AcccesLogValve will eventually produce a log entry. AcccesLogValve最终产生一个日志条目。 At least I haven't been able to produce a scenario where this is not the case. 至少我没有能够提出一种并非如此的情况。

All the access logs that I have seen are written after the request/response has been processed because it is useful to log info like the size of the response or the total processing time. 我看到的所有访问日志都是在处理请求/响应之后写入的,因为记录诸如响应大小或总处理时间之类的信息非常有用。

"If something goes wrong before that AccessLogValve will not log the request. “如果在出问题之前AccessLogValve不会记录请求。

Question 1: Is this correctly understood?" 问题1:这是否正确理解?”

No, not based on my experience. 不,不是根据我的经验。 The request/response is always logged, even if there is an error processing it. 请求/响应始终被记录,即使在处理请求时出错。 In that case the HTTP status code field ( %s in the log pattern) will contain an error code, like 500. 在这种情况下,HTTP状态代码字段(日志模式中的%s )将包含错误代码,例如500。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM