server.xml中该日志的配置是被注释了的,如果需要输出访问日志,可以取消这部分配置的注释。其中directory是日志输出的文件路径,以tomcat安装路径作为当前路径;pattern表示日志的格式,common是tomcat提供的一个标准设置格式。其具体的表达式为 %h %l %u %t “%r" %s %b,我们也可以根据需要,配置自己的pattern(直接把common替换为具体的格式表达式即可)。该日志支持的格式化参数如下。一般可以对tomcat的访问日志做日志分析,做相关的数据统计。
* %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 resolveHosts 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
* %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