Tomcat设置access日志
参考地址:http://tomcat.apache.org/tomcat-8.5-doc/config/valve.html#Access_Log_Valve
- %a - Remote IP address
- %A - Local IP address
- %b - Bytes sent, excluding HTTP headers, or '-' if zero
- %B - Bytes sent, excluding HTTP headers
- %h - Remote host name (or IP address if
enableLookupsfor the connector is 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. See also
%{xxx}pbelow. - %q - Query string (prepended with a '?' if it exists)
- %r - First line of the request (method and request URI)
- %s - HTTP status code of the response
- %S - User session 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)
There is also support to write information incoming or outgoing headers, cookies, session or request attributes and special timestamp formats. It is modeled after the Apache HTTP Server log configuration syntax. Each of them can be used multiple times with different xxx keys:
%{xxx}iwrite value of incoming header with namexxx%{xxx}owrite value of outgoing header with namexxx%{xxx}cwrite value of cookie with namexxx%{xxx}rwrite value of ServletRequest attribute with namexxx%{xxx}swrite value of HttpSession attribute with namexxx%{xxx}pwrite local (server) port (xxx==local) or remote (client) port (xxx=remote)%{xxx}twrite timestamp at the end of the request formatted using the enhanced SimpleDateFormat patternxxx
All formats supported by SimpleDateFormat are allowed in %{xxx}t. In addition the following extensions have been added:
sec- number of seconds since the epochmsec- number of milliseconds since the epochmsec_frac- millisecond fraction
These formats cannot be mixed with SimpleDateFormat formats in the same format token.
Furthermore one can define whether to log the timestamp for the request start time or the response finish time:
beginor prefixbegin:chooses the request start timeendor prefixend:chooses the response finish time
By adding multiple %{xxx}t tokens to the pattern, one can also log both timestamps.
The shorthand pattern pattern="common" corresponds to the Common Log Format defined by '%h %l %u %t "%r" %s %b'.
The shorthand pattern pattern="combined" appends the values of the Referer and User-Agent headers, each in double quotes, to the common pattern.
When Tomcat is operating behind a reverse proxy, the client information logged by the Access Log Valve may represent the reverse proxy, the browser or some combination of the two depending on the configuration of Tomcat and the reverse proxy. For Tomcat configuration options see Proxies Support and the Proxy How-To. For reverse proxies that use mod_jk, see the generic proxy documentation. For other reverse proxies, consult their documentation.
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log" suffix=".txt" pattern="%a -> %A %p %{yyyy-MM-dd HH:mm:ss}t %D %H %m %U%q %s %I %{Content-Type}i %{jsessionid}i %{Referer}i %{User-Agent}i" />
127.0.0.1 -> 127.0.0.1 8999 2017-04-21 16:07:49 116 HTTP/1.1 POST /rent-base/rent/wallet/recharge/deposit 200 http-nio-8999-exec-3 application/json; charset=utf-8 fd826bb5f92b44a1871bb1af12bb8273 - Dalvik/2.1.0 (Linux; U; Android 7.0; HUAWEI NXT-CL00 Build/HUAWEINXT-CL00)
浙公网安备 33010602011771号