1. conf/server.xmlhtml
註釋掉<Value/>節,不生成localhost_access_log。apache
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b %D" />tomcat
修改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地址若是connector的enableLookups爲false %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) 處理當前請求的線程名
以上配置的輸出日誌形式:session
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
ide