1. conf/server.xml
注释掉<Value/>节,不生成localhost_access_log。
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b %D" />
修改pattern属性,记录想要的信息:
%a - Remote IP address 远程机器地址
%A - Local IP address 服务器本机地址
%b - Bytes sent, excluding HTTP headers, or '-' if zero 发送的字节数,不包含HTTP头信息
%B - Bytes sent, excluding HTTP headers
%h - Remote host name (or IP address if enableLookups for the connector is false) 远程主机名,或者IP地址如果<span style="font-family: Arial, Helvetica, sans-serif;">connector的</span><span style="font-family: Arial, Helvetica, sans-serif;">enableLookups为false</span><span style="font-family: Arial, Helvetica, sans-serif;">
</span>%H - Request protocol 请求协议
%l - Remote logical username from identd (always returns '-')
%m - Request method (GET, POST, etc.) 请求方法
%p - Local port on which this request was received 服务器本机接收请求的端口
%q - Query string (prepended with a '?' if it exists)
%r - First line of the request (method and request URI) 请求的第一行(请求方法和URI)
%s - HTTP status code of the response HTTP响应状态码
%S - User session ID 用户会话ID
%t - Date and time, in Common Log Format 时间
%u - Remote user that was authenticated (if any), else '-'
%U - 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 处理请求的时间开销,以秒计
%F - Time taken to commit the response, in millis 提交响应的时间开销,以毫秒计
%I - Current request thread name (can compare later with stacktraces) 处理当前请求的线程名
以上配置的输出日志形式:
172.31.105.49 - - [21/May/2014:15:54:42 +0800] "POST /upload-service/service/upload HTTP/1.1" 200 26
172.31.104.17 - - [21/May/2014:15:54:42 +0800] "POST /upload-service/service/upload HTTP/1.1" 500 6478
172.31.105.93 - - [21/May/2014:15:54:43 +0800] "POST /upload-service/service/upload HTTP/1.1" 200 26
172.31.106.49 - - [21/May/2014:15:54:43 +0800] "POST /upload-service/service/upload HTTP/1.1" 500 6478
172.31.104.25 - - [21/May/2014:15:54:43 +0800] "POST /upload-service/service/upload HTTP/1.1" 500 6478
172.31.104.125 - - [21/May/2014:15:54:44 +0800] "POST /upload-service/service/upload HTTP/1.1" 200 24
172.31.104.133 - - [21/May/2014:15:54:44 +0800] "POST /upload-service/service/upload HTTP/1.1" 500 6478
172.31.105.217 - - [21/May/2014:15:54:44 +0800] "POST /upload-service/service/upload HTTP/1.1" 500 6478
172.31.105.149 - - [21/May/2014:15:54:44 +0800] "POST /upload-service/service/upload HTTP/1.1" 500 6478
172.31.106.177 - - [21/May/2014:15:54:44 +0800] "POST /upload-service/service/upload HTTP/1.1" 500 6478
172.31.106.185 - - [21/May/2014:15:54:44 +0800] "POST /upload-service/service/upload HTTP/1.1" 200 26
172.31.105.169 - - [21/May/2014:15:54:44 +0800] "POST /upload-service/service/upload HTTP/1.1" 500 6478
172.31.104.125 - - [21/May/2014:15:54:44 +0800] "POST /upload-service/service/upload HTTP/1.1" 200 26
172.31.104.201 - - [21/May/2014:15:54:45 +0800] "POST /upload-service/service/upload HTTP/1.1" 200 26
172.31.106.137 - - [21/May/2014:15:54:45 +0800] "POST /upload-service/service/upload HTTP/1.1" 500 6478
172.31.103.73 - - [21/May/2014:15:54:45 +0800] "POST /upload-service/service/upload HTTP/1.1" 200 26
172.31.105.185 - - [21/May/2014:15:54:45 +0800] "POST /upload-service/service/upload HTTP/1.1" 200 26
172.31.105.37 - - [21/May/2014:15:54:46 +0800] "POST /upload-service/service/upload HTTP/1.1" 200 26
http://tomcat.apache.org/tomcat-7.0-doc/config/valve.html#Access Log Valve