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 ...
随机推荐
- Linux Process/Thread Creation、Linux Process Principle、sys_fork、sys_execve、glibc fork/execve api sourcecode
相关学习资料 linux内核设计与实现+原书第3版.pdf(.3章) 深入linux内核架构(中文版).pdf 深入理解linux内核中文第三版.pdf <独辟蹊径品内核Linux内核源代码导读 ...
- MyEclipse------遍历某个路径下的(所有或特定)文件和目录
usebean包(自己定义的,在src文件夹下面)里的java文件 FileAccept.java package usebean; import java.io.File; import java. ...
- linux学习之系统管理、网络配置、软件安装
一.ifconfig,命令查看linux系统IP 二.su切换到root下(已是root用户不用切换),使用setup命令启用界面操作 CentOS我安装的是Minimal版本,没有安 ...
- DEDECMS全版本gotopage变量XSS ROOTKIT 0DAY
影响版本: DEDECMS全版本 漏洞描叙: DEDECMS后台登陆模板中的gotopage变量未效验传入数据,导致XSS漏洞. \dede\templets\login.htm 65行左右 < ...
- rwsr-sr-x类似权限设置
如何设置suid/guid? 如果希望设置suid,那么就将相应的权限位之前的那一位设置为4:如果希望设置guid,那么就将相应的权限位之前的那一位设置为2:如果希望两者都置位,那么将相应的权限位之前 ...
- Javascript动态调整文章的行距、字体、颜色,及打印页面和关闭窗口功能
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Highways(prim & MST)
Highways Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 23421 Accepted: 10826 Descri ...
- 畅通工程再续(MST)
畅通工程再续 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- 探讨关于C#中Foreach的本质
一.为什么数组和集合可以使用foreach遍历 01. 因为数组和集合都实现了IEnumerable接口,该接口中只有一个方法,GetEnumerator() 02.数组类型是从抽象基类型 Array ...
- SELinux入门
导读 如果你在之前的Linux生涯中都禁用或忽略了SELinux,这篇文章就是专门为你写的:这是一篇对存在于你的Linux桌面或服务器之下的SELinux系统的介绍,它能够限制权限,甚至消除程序或守护 ...