Tomcat的访问日志-localhost_access_log和记录Post请求参数
来源:互联网 发布:电玩游戏平台源码 编辑:程序博客网 时间:2024/05/17 22:36
- tomcat的日志分类
http://blog.csdn.net/fly910905/article/details/78463909
- tomcat产生的访问日志数据 【localhost_access_log.Y-M-D.txt】
它记录的访问的时间,IP,访问的资料等相关信息
- 首先是配置tomcat访问日志数据,配置的方式如下
- 打开${catalina}/conf/server.xml文件
- 注:${catalina}是tomcat的安装目录
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" pattern="%h %l %u %t "%r" %s %b"
prefix="localhost_access_log" suffix=".txt"/>
tomcat访问日志关闭:只需要将
${catalina}/conf/server.xml里面的下列申明注释掉再重启tomcat就好
参数说明:
- 具体的日志产生样式说明如下(从官方文档中摘录)
* %a - Remote IP address // 这是记录访问者的IP,在日志里是127.0.0.1
* %A - Local IP address // 这是记录本地服务器的IP,在日志里是192.168.254.108
* %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) //服务器的名称。如果resolveHosts为false的话,这里就是IP地址了,例如我的日志里是10.217.14.16
* %H - Request protocol //访问者的协议,这里是HTTP/1.0
* %l - Remote logical username from identd (always returns '-') // 官方解释:Remote logical username from identd (可能这样翻译:记录浏览者进行身份验证时提供的名字)(always returns '-')
* %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) // 比如你访问的是aaa.jsp?bbb=ccc,那么这里就显示?bbb=ccc,就是querystring的意思
* %r - First line of the request (method and request URI) // First line of the request (method and request URI) 请求的方法和URL
* %s - HTTP status code of the response // http的响应状态码
* %S - User session ID // 用户的session ID,这个session ID大家可以另外查一下详细的解释,反正每次都会生成不同的session ID
* %t - Date and time, in Common Log Format // 请求时间
* %u - Remote user that was authenticated (if any), else '-' // 得到了验证的访问者,否则就是"-"
* %U - Requested URL path // 访问的URL地址,我这里是/rightmainima/leftbott4.swf
* %v - Local server name // 服务器名称,可能就是你url里面写的那个吧,我这里是localhost
* %D - Time taken to process the request, in millis // 请求消耗的时间,以毫秒记
* %T - Time taken to process the request, in seconds //请求消耗的时间,以秒记
There is also support to write information from the cookie, incoming header, the Session or something else in the ServletRequest.
It is modeled after the apache syntax:
* %{xxx}i for incoming headers
* %{xxx}c for a specific cookie
* %{xxx}r xxx is an attribute in the ServletRequest
* %{xxx}s xxx is an attribute in the HttpSession
- 示例【格式为 %h %l %u %t "%r" %s %b】
140.205.201.39 - - [31/Aug/2017:17:06:52 +0800] "GET /clusters.jsf HTTP/1.1" 404 -
60.191.38.77 - - [31/Aug/2017:17:11:35 +0800] "GET / HTTP/1.1" 404 -
61.232.253.54 - - [31/Aug/2017:19:04:53 +0800] "GET / HTTP/1.1" 404 -
100.116.151.190 - - [31/Aug/2017:20:45:17 +0800] "GET /CloudPayment/bill/querySelfPayList.do HTTP/1.0" 200 60
100.116.41.2 - - [31/Aug/2017:20:45:34 +0800] "GET /CloudPayment/user/pay.do HTTP/1.0" 200 1422
100.116.151.145 - - [31/Aug/2017:20:46:22 +0800] "GET /CloudPayment/user/pay.do HTTP/1.0" 200 1422
100.116.41.41 - - [31/Aug/2017:20:46:42 +0800] "GET /CloudPayment/user/pay.do HTTP/1.0" 200 1422
100.116.151.181 - - [31/Aug/2017:20:47:21 +0800] "GET /CloudPayment/user/pay.do HTTP/1.0" 200 1422
100.116.151.181 - - [31/Aug/2017:20:47:22 +0800] "GET /CloudPayment/user/pay.do HTTP/1.0" 200 1422
- 记录Post请求参数
另外%r参数能打印出请求的url和get参数。如果url指定访问方式是post,post的参数是打印不出来的。当需要打印post参数,该怎么办?
server.xml配置tomcat访问日志格式配置,在config/server.xml里Host标签下加上
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" [%{postdata}r] %s %{Referer}i %{User-Agent}i %T %b" />
postdata过滤器package com.xiaoxiliu
import java.io.IOException;
import java.util.Enumeration;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public final class PostDataDumperFilter implements Filter {
Logger logger = LoggerFactory.getLogger(getClass());
private FilterConfig filterConfig = null;
public void destroy() {
this.filterConfig = null;
}
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
if (filterConfig == null)
return;
Enumeration<String> names = request.getParameterNames();
StringBuilder output = new StringBuilder();
while (names.hasMoreElements()) {
String name = (String) names.nextElement();
output.append(name).append("=");
String values[] = request.getParameterValues(name);
for (int i = 0; i < values.length; i++) {
if (i > 0) {
output.append("' ");
}
output.append(values[i]);
}
if (names.hasMoreElements())
output.append("&");
}
request.setAttribute("postdata", output);
logger.debug("postdata: " + output);
chain.doFilter(request, response);
}
public void init(FilterConfig filterConfig) throws ServletException {
this.filterConfig = filterConfig;
}
}
在web.xml中添加配置该filter<filter>
<filter-name>post-data-dumper-filter</filter-name>
<filter-class>com.xiaoxiliu.PostDataDumperFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>post-data-dumper-filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
参考来源:http://blog.csdn.net/qq_30121245/article/details/52861935
阅读全文
0 0
- Tomcat的访问日志-localhost_access_log和记录Post请求参数
- Tomcat的访问日志-localhost_access_log和记录Post请求参数
- tomcat访问(access)日志配置、记录Post请求参数
- tomcat的acess_log打印post请求参数,分析日志
- tomcat localhost_access_log查看http请求
- 在nginx日志的access log中记录post请求的参数值
- nginx日志记录post的参数
- GET请求和POST请求的参数
- Tomcat 访问日志记录
- tomcat记录访问日志
- 通过Nginx,Tomcat访问日志(access log)记录请求耗时
- 通过Nginx,Tomcat访问日志(access log)记录请求耗时
- php在服务器端记录客户端请求的所有GET和POST参数
- 让nginx日志支持记录POST请求
- nginx记录响应与POST请求日志
- 统计打印localhost_access_log.20150218-20.txt.gz中单次访问超过500ms的请求数(friends_timeline.json接口) zcat localhost_
- node中,GET请求和POST请求的参数
- ajax和json的post和get请求参数配置
- 初见Spring之JDBC
- tiny4412 设备树之pinctrl(番外)
- 磁盘分区
- 扩展欧几里德板子 poj2142
- FZU 2082 过路费(树链剖分,边权)
- Tomcat的访问日志-localhost_access_log和记录Post请求参数
- 网页更容易被搜索引擎收录--善用标签
- 集合,增删改查,事务
- Javascript怎么将秒转换为时间
- Mathematica
- 简单的springboot使用freemarker
- Ajax的简单用法
- Vue框架中关于vue-lazyload的简单应用实例(学习笔记③)
- 深入MNIST(1)