Java/Tomcat 独立,如何记录/访问所有 HTTP GET 请求

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3017188/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 15:36:12  来源:igfitidea点击:

Java/Tomcat standalone, how to log/access all the HTTP GET requests

javatomcatlogging

提问by NoozNooz42

I'm running Tomcat in standalone mode. The "standalone" part is very important: I am notgoing to install Apache in front of Tomcat.

我在独立模式下运行 Tomcat。“独立”部分非常重要:我不会在Tomcat之前安装Apache。

In my question here, about how to implement a "web bug", I got a great answer: Java webapp: how to implement a web bug (1x1 pixel)?

在我的问题中,关于如何实现“网络错误”,我得到了一个很好的答案:Java webapp:如何实现网络错误(1x1 像素)?

However the answer states:

然而,答案指出:

In your access logs, you can count for your jpg - the output should be"

127.0.0.1 - - [10/Jun/2010:11:38:53 +0530] "GET /mywebapp/jsp/invisible.jpg?1276150133362 HTTP/1.1" 200 991

在您的访问日志中,您可以计算您的 jpg - 输出应该是“

127.0.0.1 - - [10/Jun/2010:11:38:53 +0530] "GET /mywebapp/jsp/invisible.jpg?1276150133362 HTTP/1.1" 200 991

But, as I feared, I cannot find such logs.

但是,正如我所担心的,我找不到这样的日志。

... $ cat apache-tomcat-6.0.26/logs/* | grep GET | wc -l

... $ cat apache-tomcat-6.0.26/logs/* | 获取 | wc -l

0

0

There are a lot of logs. My webapp's custom logs are definitely logged.

有很多日志。我的 webapp 的自定义日志肯定被记录了。

So I've got a few related questions:

所以我有几个相关的问题:

  • Does "Tomcat standalone" log every HTTP GET request by default?

  • If yes, where are every HTTP GET requests logged by default? (how could I have found them myselves?)

  • If no, can "Tomcat standalone" be configured to log every HTTP GET request?

  • 默认情况下,“Tomcat 独立”是否会记录每个 HTTP GET 请求?

  • 如果是,默认情况下每个 HTTP GET 请求记录在哪里?(我怎么能自己找到它们?)

  • 如果不是,是否可以将“Tomcat 独立”配置为记录每个 HTTP GET 请求?

Note that I know that in my case I can add custom logging alongside with my web bug .jspand search for that in the logs, but that is not my question here.

请注意,我知道在我的情况下,我可以将自定义日志记录与我的网络错误.jsp一起添加并在日志中搜索,但这不是我在这里的问题。

My question here is really about how Tomcat standalone (once again, the standalone is very important) deals with logging of all the HTTP GET requests.

我在这里的问题实际上是关于 Tomcat 独立(再次强调,独立是非常重要的)如何处理所有 HTTP GET 请求的日志记录。

采纳答案by Richard Fearn

It doesn't log requests by default, but will do if you uncomment this valve in conf/server.xml:

默认情况下它不会记录请求,但如果您取消注释此阀,则会这样做conf/server.xml

<Valve className="org.apache.catalina.valves.AccessLogValve"
    directory="logs" prefix="localhost_access_log." suffix=".txt"
    pattern="common" resolveHosts="false"/>