Tomcat 记录访问日志字段详解

 

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进行比较)

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值