-
server.tomcat.accesslog.prefix = access
server.tomcat.accesslog.suffix = .log
server.tomcat.accesslog.file-date-format = -yyyyMMddHH有的时候我们要使用日志分析工具对日志进行分析,需要对日志进行格式化,比如,要把accessLog格式化成这样的格式
c-ip s-ip x-InstancePort date time-taken x-Protocol cs-method cs-uri sc-status x-ResponseSize bytes x-Referrer x-UserAgent
在tomcat的conf/server.xml加入配置:
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log" suffix=".txt" pattern="%{X-Real-IP}i %A %p %{yyyy-MM-dd HH:mm:ss}t %D %H %m %U %s %B %B %{Referer}i %{User-Agent}i" />
关于accessLog的官方说明,请看 http://tomcat.apache.org/tomcat-8.0-doc/config/valve.html#Access_Logging
常用配置如下:
- %a – Remote IP address –远程IP地址
- %A – Local IP address –本地IP地址
- %b – Bytes sent, excluding HTTP headers, or ‘-‘ if zero –发送的字节数(Bytes sent), 不包括HTTP headers的字节,如果为0则展示’-‘
- %B – Bytes sent, excluding HTTP headers –发送的字节数(Bytes sent), 不包括HTTP headers的字节
- %h – Remote host name (or IP address if
enableLookups
for the connector is false) –远程主机名称(如果resolveHosts为false则展示IP) - %H – Request protocol –请求协议
- %l – Remote logical username from identd (always returns ‘-‘) –远程用户名,始终为’-‘(Remote logical username from identd)
- %m – Request method (GET, POST, etc.) –请求的方法(GET, POST等)
- %p – Local port on which this request was received. See also
%{xxx}p
below. –接受请求的本地端口 - %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 –response的HTTP状态码(200,404等)
- %S – User session ID –用户的session ID
- %t – Date and time, in Common Log Format –日期和时间,Common Log Format格式
- %u – Remote user that was authenticated (if any), 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 –处理请求的时间,单位为秒
- %F – Time taken to commit the response, in millis –提交响应的时间,以毫秒为单位
- %I – Current request thread name (can compare later with stacktraces) –当前请求的线程名
Access Log中也支持cookie,请求header,响应headers,Session或者其他在ServletRequest中的对象的信息
%{xxx}i
write value of incoming header with namexxx
%{xxx}o
write value of outgoing header with namexxx
%{xxx}c
write value of cookie with namexxx
%{xxx}r
write value of ServletRequest attribute with namexxx
%{xxx}s
write value of HttpSession attribute with namexxx
%{xxx}p
write local (server) port (xxx==local
) or remote (client) port (xxx=remote
)%{xxx}t
write timestamp at the end of the request formatted using the enhanced SimpleDateFormat patternxxx
如果tomcat前面有nginx做负载均衡,则要修改nginx的配置
Nginx的server主机配置段中添加:
proxy_set_header X-Real-IP $remote_addr; #真实的远端IP地址
so 再tomcat accessLog用%{X-Real-IP}i 获取即可
-
原文地址:http://www.cnblogs.com/yanlai/p/16869699.html
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,请务用于商业用途!
3. 如果你也有好源码或者教程,可以到用户中心发布,分享有积分奖励和额外收入!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
7. 如遇到加密压缩包,默认解压密码为"gltf",如遇到无法解压的请联系管理员!
8. 因为资源和程序源码均为可复制品,所以不支持任何理由的退款兑现,请斟酌后支付下载
声明:如果标题没有注明"已测试"或者"测试可用"等字样的资源源码均未经过站长测试.特别注意没有标注的源码不保证任何可用性