Tomcat AccessLog 格式化
有的时候我们要使用日志分析工具对日志进行分析,需要对日志进行格式化,比如,要把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
enableLookupsfor 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}pbelow. --接受请求的本地端口 - %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}iwrite value of incoming header with namexxx%{xxx}owrite value of outgoing header with namexxx%{xxx}cwrite value of cookie with namexxx%{xxx}rwrite value of ServletRequest attribute with namexxx%{xxx}swrite value of HttpSession attribute with namexxx%{xxx}pwrite local (server) port (xxx==local) or remote (client) port (xxx=remote)%{xxx}twrite 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地址
然后再tomcat accessLog用%{X-Real-IP}i 获取即可
Tomcat AccessLog 格式化的更多相关文章
- tomcat accesslog日志扩展
由于工作需要,最近对tomcat的日志进行了一些研究,发现其日志大致可以分为两类,一类是运行日志,即平常我们所说的catalina.out日志,由tomcat内部代码调用logger打印出来的:另一类 ...
- 配置spring boot 内置tomcat的accessLog日志
#配置内置tomcat的访问日志server.tomcat.accesslog.buffered=trueserver.tomcat.accesslog.directory=/home/hygw/lo ...
- Tomcat access log配置
在tomcat的access中打印出请求的情况可以帮助我们分析问题,通常比较关注的有访问IP.线程号.访问url.返回状态码.访问时间.持续时间. 在Spring boot中使用了内嵌的tomcat, ...
- springboot中配置tomcat的access log
在tomcat的access中打印出请求的情况可以帮助我们分析问题,通常比较关注的有访问IP.线程号.访问url.返回状态码.访问时间.持续时间. 在Spring boot中使用了内嵌的tomcat, ...
- Access Logging Tomcat
73.6 Configure Access Logging server.tomcat.accesslog.buffered=true # Buffer output such that it is ...
- springboot tomcat配置参数列表
springboot tomcat的配置选项大全 server. Port = xxxx server. Address = server. contextPath = server. display ...
- tomcat和springboot访问日志及分析
1.Tomcat设置访问日志 <Host name="localhost" appBase="webapps" unpackWARs="true ...
- Spring Boot tomcat
定制内嵌 Tomcat 设置内嵌Tomcat的端口 Spring Boot 内嵌的 Tomcat 服务器默认运行在 8080 端口.如果,我们需要修改Tomcat的端口,我们可以在 src/main/ ...
- Spring Boot Tomcat配置详解
参数配置容器 server.xx开头的是所有servlet容器通用的配置,server.tomcat.xx开头的是tomcat特有的参数,其它类似. 所有参数绑定配置类:org.springframe ...
随机推荐
- cogs896 圈奶牛
描述 农夫约翰想要建造一个围栏用来围住他的奶牛,可是他资金匮乏.他建造的围栏必须包括他的奶牛喜欢吃草的所有地点.对于给出的这些地点的坐标,计算最短的能够围住这些点的围栏的长度. PROGRAM NAM ...
- Laravel5.1 启动详解
借鉴: Laravel所有请求的入口文件是:/public/index.php,代码如下 <?php /*|------------------------------------------- ...
- linux(Debian)下安装与MySql的安装、卸载、配置及使用
参考资料:http://www.cnblogs.com/xusir/p/3334217.html 以下是简要记录. 一.安装 安装:apt-get install mysql-server mysql ...
- 锋利的jQuery-7--一个$.fn.color插件的编写过程
编写一个设置和获取元素的color的插件: 首先实现第一个功能,设置: ;(function($){ $.fn.extend({ color:function(value){ return this. ...
- JAVA如何调用C/C++方法
JAVA如何调用C/C++方法 2013-05-27 JAVA以其跨平台的特性深受人们喜爱,而又正由于它的跨平台的目的,使得它和本地机器的各种内部联系变得很少,约束了它的功能.解决JAVA对本地操作的 ...
- linux c程序中获取shell脚本输出的实现方法
linux c程序中获取shell脚本输出的实现方法 1. 前言Unix界有一句名言:“一行shell脚本胜过万行C程序”,虽然这句话有些夸张,但不可否认的是,借助脚本确实能够极大的简化一些编程工作. ...
- Linux 下的另一个密码破解工具medusa
首先,本人在此声明 此工具许合理利用非法破解很可能会被发现的因为这是一个暴力破解方式需要不断的尝试登陆服务器 ,服务器上的检测软件很快可以跟踪到并锁定你的IP地址 请大家切勿用于非法手段- -! me ...
- HNU 12812 Broken Audio Signal
题目链接:http://acm.hnu.cn/online/?action=problem&type=show&id=12812 一直弄错了一个题意,教训啊,比赛最怕的就是弄错题意了 ...
- NGUI之scroll view制作,以及踩的坑总结
http://blog.csdn.net/monzart7an/article/details/23878505 链接: http://game.ceeger.com/forum/read.php?t ...
- Linux 在 i 节点表中的磁盘地址表中,若一个文件的长度是从磁盘地址表的第 1 块到第 11 块 解析?
面试题: 在 i 节点表中的磁盘地址表中,若一个文件的长度是从磁盘地址表的第 1 块到第 11块,则该文件共占有 B 块号.A 256 B 266 C 11 D 256×10 linux文件系统是L ...