tomcat日志文件格式配置实例

发布时间:2020-05-01编辑:脚本学堂
有关tomcat日志文件格式的教程,tomcat日志文件格式配置方法与输出实例,需要的朋友参考下。

tomcat日志文件格式

在server.xml文件中配置:
 

<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log." suffix=".txt" pattern="%h %l %u %t %r %s %b %D" resolveHosts="false"/>
 

其中:pattern="%h %l %u %t %r %s %b %D" 为配置的日志输出格式。
或patten="common"
或patten=""combined

common的值:%h %l %u %t %r %s %b
combined的值:%h %l %u %t %r %s %b %{Referer}i %{User-Agent}i
prefix="localhost_access_log.":为日志文件名前准。

%a – 远程主机的IP (Remote IP address)
%A – 本机IP (Local IP address)
%b – 发送字节数,不包含HTTP头,0字节则显示 ‘-’ (Bytes sent, excluding HTTP headers, or ‘-’ if no bytes
were sent)
%B – 发送字节数,不包含HTTP头 (Bytes sent, excluding HTTP headers)
%h – 远程主机名 (Remote host name)
%H – 请求的具体协议,HTTP/1.0 或 HTTP/1.1 (Request protocol)
%l – 远程用户名,始终为 ‘-’ (Remote logical username from identd (always returns ‘-’))
%m – 请求方式,GET, POST, PUT (Request method)
%p – 本机端口 (Local port)
%q – 查询串 (Query string (prepended with a ‘?’ if it exists, otherwise
an empty string)
%r – HTTP请求中的第一行 (First line of the request)
%s – HTTP状态码 (HTTP status code of the response)
%S – 用户会话ID (User session ID)
%t – 访问日期和时间 (Date and time, in Common Log Format format)
%u – 已经验证的远程用户 (Remote user that was authenticated
%U – 请求的URL路径 (Requested URL path)
%v – 本地服务器名 (Local server name)
%D – 处理请求所耗费的毫秒数 (Time taken to process the request, in millis)
%T – 处理请求所耗费的秒数 (Time taken to process the request, in seconds)

输出格式:
 

10.200.7.116 - - [23/Feb/2011:17:25:13 +0800] GET /search/gettotalnum.do HTTP/1.1 200 137 1