什么是Tomcat中的本地主机访问日志?

16
我想了解Tomcat中的本地主机访问日志是什么?我们可以通过这些日志监控哪些信息,以及如何通过Java程序读取它们?
3个回答

13

访问日志包含每个请求到达服务器时的相关信息。它可用于跟踪页面点击次数、用户会话活动等,因为它记录了所有传入的请求,包括时间戳、请求 HTTP 方法和 HTTP 响应代码。

示例日志语句如下:

46.181.252.151  - - [22/Feb/2019:19:04:19 +0000] "GET /task/768476366 HTTP/1.1" 200 6765
36.231.298.259  - - [22/Feb/2019:19:04:20 +0000] "GET /doc/wallet/9855563 HTTP/1.1" 200 45564

常见的日志模式为"%h %l %u %t "%r" %s %b"。
%h – Remote hostname (or IP address if the resolveHosts attribute is set to false; by default the value is false).
%l – Remote logical user name; this is always a hyphen (-).
%u – Remote user that has been authenticated. In the example, “admin” and a hyphen (-). If there is none, it’s a hyphen (-).
%t – Date and time in common log file format.
%r – The first line of the request. In the example, “GET / HTTP/1.1” (note that this is configured to be shown within quotes (“”)).
%s – The HTTP status code of the response. In the example 200 is the OK status.
%b – Bytes sent count, excluding HTTP headers, and shows a hyphen (-) if zero.

更多细节请点击这里


7

Tomcat中的localhost访问日志包含与请求相关的信息,例如:

  1. IP地址
  2. 时间
  3. 请求方法(GET或POST)
  4. 请求所涉及的资源。

2
如其名,访问日志是一种特殊的日志,包含有关主机上任何资源的日志和使用活动的信息。
我强烈建议您阅读这里的它文档。
如果您确实需要读取某个应用程序的访问日志,请注意,由于一些明显的原因,这可能不是一个好主意。但如果您确实要读取它们,它们是简单的文件,驻留在$TOMCAT_DIR$/logs文件夹中,您可以在它们上执行常规IO操作。只需确保验证文件锁定以及对它们的读取/写入权限。
只是一个小问题:您将无法读取Tomcat用于特定日期的文件。

日志记录的最短时间是多少?上个月在我的本地主机访问日志中,Tomcat每天以本地IP地址记录一分钟。这个月我注意到连续两个日志之间的差异超过1小时,并且这种情况在整个月都发生了。为什么它不会每分钟写入?你有任何想法吗? - Anurag Sharma

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接