1. tomcat访问日志
默认 tomcat 不记录访问日志,如下方法可以使 tomcat 记录访问日志
编辑 ${catalina}/conf/server.xml 文件. 注 :${catalina} 是 tomcat 的安装目录
把以下的注释 (<!-- -->) 去掉即可。
<!--
<Valve className="org.apache.catalina.valves.AccessLogValve"
directory="logs" prefix="localhost_access_log." suffix=".txt"
pattern="common" resolveHosts="false"/>
-->
2. 如何配置
修改 1 后
该项值可以为: common 与 combined ,这两个预先设置好的格式对应的日志输出内容如下:
common 的值: %h %l %u %t %r %s %b
combined 的值: %h %l %u %t %r %s %b %{Referer}i %{User-Agent}i
pattern 也可以根据需要自由组合, 例如 pattern="%h %l"
3.字段详情
%a - Remote IP address
-- 远程IP地址
%A - Local IP address
-- 本地IP地址发送的
%b - Bytes sent, excluding HTTP headers, or '-' if zero
-- 字节,不包括HTTP头,如果为0,则为“-”发送的
%B - Bytes sent, excluding HTTP headers
-- 发送的字节,不包括HTTP头
%h - Remote host name (or IP address if resolveHosts is false)
-- 远程主机名(或IP地址,如果resolveHosts为假)
%H - Request protocol
-- 请求协议
%l - Remote logical username from identd (always returns '-')
-- eguesu PLoLou来自identd的远程逻辑用户名(总是返回1-1)
%m - Request method (GET, POST, etc.)
-- 请求方法(GET、POST等)
%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)
-- 请求的第一行(方法和请求URD响应
%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 '-'
-- 经过身份验证的远程用户(如果有的话),else '-'
%U - Requested URL path
-- 请求的URL路径
%v - Local server name
-- 本地服务器名称
%D - Time taken to process the request, in millis
-- 处理请求所花费的时间,单位为 毫
%T - Time taken to process the request, in seconds
-- 处理请求所花费的时间, 单位为 秒
%I - Current request thread name (can compare later with stacktraces)
-- 当前请求线程名称(可以稍后与stacktrace进行比较)