tomcat访问日志设置

本文介绍了如何在Tomcat中设置访问日志,包括在conf/server.xml文件中注释或修改AccessLogValve配置,以控制日志的生成和定制日志信息的格式。
摘要由CSDN通过智能技术生成

1. conf/server.xml

注释掉<Value/>节,不生成localhost_access_log

<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log." suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b
 %D" />

修改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地址如果<span style="font-family: Arial, Helvetica, sans-serif;">connector的</span><span style="font-family: Arial, Helvetica, sans-serif;">enableLookups为false</span><span style="font-family: Arial, Helvetica, sans-serif;">
</span>%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) 处理当前请求的线程名

以上配置的输出日志形式:

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值