一、tomcat 设置 Request_Dumper_Filter ,打印 hearder
https://tomcat.apache.org/tomcat-9.0-doc/config/filter.html#Request_Dumper_Filter
修改 CATALINA_BASE/conf/web.xml
,在 <web-app> </web-app>
之间添加Request Dumper Filter,如下
<web-app>
...
<!-- == Request Dumper Filter == -->
<filter>
<filter-name>requestdumper</filter-name>
<filter-class>
org.apache.catalina.filters.RequestDumperFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>requestdumper</filter-name>
<url-pattern>*</url-pattern>
</filter-mapping>
</web-app>
日志输出在 catalina.out,如下:
31-Oct-2023 17:44:40.464 INFO [http-nio-8080-exec-4] org.apache.catalina.filters.RequestDumperFilter.doLog http-nio-8080-exec-4 START TIME =31-Oct-2023 17:44:40
31-Oct-2023 17:44:40.464 INFO [http-nio-8080-exec-4] org.apache.catalina.filters.RequestDumperFilter.doLog http-nio-8080-exec-4 requestURI=/com.ifp.wmsbusiness/accountMessageTemplate/queryAccountMessageTemplateList
31-Oct-2023 17:44:40.464 INFO [http-nio-8080-exec-4] org.apache.catalina.filters.RequestDumperFilter.doLog http-nio-8080-exec-4 authType=null
31-Oct-2023 17:44:40.464 INFO [http-nio-8080-exec-4] org.apache.catalina.filters.RequestDumperFilter.doLog http-nio-8080-exec-4 characterEncoding=UTF-8
31-Oct-2023 17:44:40.464 INFO [http-nio-8080-exec-4] org.apache.catalina.filters.RequestDumperFilter.doLog http-nio-8080-exec-4 contentLength=63
31-Oct-2023 17:44:40.464 INFO [http-nio-8080-exec-4] org.apache.catalina.filters.RequestDumperFilter.doLog http-nio-8080-exec-4 contentType=application/x-www-form-urlencoded
31-Oct-2023 17:44:40.464 INFO [http-nio-8080-exec-4] org.apache.catalina.filters.RequestDumperFilter.doLog http-nio-8080-exec-4 contextPath=/com.ifp.wmsbusiness
31-Oct-2023 17:44:40.464 INFO [http-nio-8080-exec-4] org.apache.catalina.filters.RequestDumperFilter.doLog http-nio-8080-exec-4 header=host=10.51.16.5
31-Oct-2023 17:44:40.464 INFO [http-nio-8080-exec-4] org.apache.catalina.filters.RequestDumperFilter.doLog http-nio-8080-exec-4 header=x-real-ip=10.41.99.232
31-Oct-2023 17:44:40.464 INFO [http-nio-8080-exec-4] org.apache.catalina.filters.RequestDumperFilter.doLog http-nio-8080-exec-4 header=remote-host=10.41.99.232
31-Oct-2023 17:44:40.464 INFO [http-nio-8080-exec-4] org.apache.catalina.filters.RequestDumperFilter.doLog http-nio-8080-exec-4 header=x-forwarded-for=10.41.99.232
31-Oct-2023 17:44:40.464 INFO [http-nio-8080-exec-4] org.apache.catalina.filters.RequestDumperFilter.doLog http-nio-8080-exec-4 header=content-length=63
31-Oct-2023 17:44:40.464 INFO [http-nio-8080-exec-4] org.apache.catalina.filters.RequestDumperFilter.doLog http-nio-8080-exec-4 header=usertrackname=admin
31-Oct-2023 17:44:40.464 INFO [http-nio-8080-exec-4] org.apache.catalina.filters.RequestDumperFilter.doLog http-nio-8080-exec-4 header=accept=application/json, text/plain, */*
31-Oct-2023 17:44:40.464 INFO [http-nio-8080-exec-4] org.apache.catalina.filters.RequestDumperFilter.doLog http-nio-8080-exec-4 header=platformflag=3
31-Oct-2023 17:44:40.465 INFO [http-nio-8080-exec-4] org.apache.catalina.filters.RequestDumperFilter.doLog http-nio-8080-exec-4 header=user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36
31-Oct-2023 17:44:40.465 INFO [http-nio-8080-exec-4] org.apache.catalina.filters.RequestDumperFilter.doLog http-nio-8080-exec-4 header=content-type=application/x-www-form-urlencoded
31-Oct-2023 17:44:40.465 INFO [http-nio-8080-exec-4] org.apache.catalina.filters.RequestDumperFilter.doLog http-nio-8080-exec-4 header=origin=http://10.51.16.5
31-Oct-2023 17:44:40.465 INFO [http-nio-8080-exec-4] org.apache.catalina.filters.RequestDumperFilter.doLog http-nio-8080-exec-4 header=referer=http://10.51.16.5/wmsclient/
31-Oct-2023 17:44:40.465 INFO [http-nio-8080-exec-4] org.apache.catalina.filters.RequestDumperFilter.doLog http-nio-8080-exec-4 header=accept-encoding=gzip, deflate
31-Oct-2023 17:44:40.465 INFO [http-nio-8080-exec-4] org.apache.catalina.filters.RequestDumperFilter.doLog http-nio-8080-exec-4 header=accept-language=zh-CN,zh;q=0.9
31-Oct-2023 17:44:40.465 INFO [http-nio-8080-exec-4] org.apache.catalina.filters.RequestDumperFilter.doLog http-nio-8080-exec-4 locale=zh_CN
31-Oct-2023 17:44:40.465 INFO [http-nio-8080-exec-4] org.apache.catalina.filters.RequestDumperFilter.doLog http-nio-8080-exec-4 method=POST
31-Oct-2023 17:44:40.465 INFO [http-nio-8080-exec-4] org.apache.catalina.filters.RequestDumperFilter.doLog http-nio-8080-exec-4 parameter=pageNo=1
31-Oct-2023 17:44:40.465 INFO [http-nio-8080-exec-4] org.apache.catalina.filters.RequestDumperFilter.doLog http-nio-8080-exec-4 parameter=pageSize=10
31-Oct-2023 17:44:40.465 INFO [http-nio-8080-exec-4] org.apache.catalina.filters.RequestDumperFilter.doLog http-nio-8080-exec-4 parameter=templateState=
31-Oct-2023 17:44:40.465 INFO [http-nio-8080-exec-4] org.apache.catalina.filters.RequestDumperFilter.doLog http-nio-8080-exec-4 parameter=templateTitle=
31-Oct-2023 17:44:40.465 INFO [http-nio-8080-exec-4] org.apache.catalina.filters.RequestDumperFilter.doLog http-nio-8080-exec-4 parameter=templateId=
31-Oct-2023 17:44:40.465 INFO [http-nio-8080-exec-4] org.apache.catalina.filters.RequestDumperFilter.doLog http-nio-8080-exec-4 pathInfo=null
31-Oct-2023 17:44:40.465 INFO [http-nio-8080-exec-4] org.apache.catalina.filters.RequestDumperFilter.doLog http-nio-8080-exec-4 protocol=HTTP/1.1
31-Oct-2023 17:44:40.465 INFO [http-nio-8080-exec-4] org.apache.catalina.filters.RequestDumperFilter.doLog http-nio-8080-exec-4 queryString=null
31-Oct-2023 17:44:40.465 INFO [http-nio-8080-exec-4] org.apache.catalina.filters.RequestDumperFilter.doLog http-nio-8080-exec-4 remoteAddr=127.0.0.1
31-Oct-2023 17:44:40.465 INFO [http-nio-8080-exec-4] org.apache.catalina.filters.RequestDumperFilter.doLog http-nio-8080-exec-4 remoteHost=127.0.0.1
31-Oct-2023 17:44:40.465 INFO [http-nio-8080-exec-4] org.apache.catalina.filters.RequestDumperFilter.doLog http-nio-8080-exec-4 remoteUser=null
31-Oct-2023 17:44:40.465 INFO [http-nio-8080-exec-4] org.apache.catalina.filters.RequestDumperFilter.doLog http-nio-8080-exec-4 requestedSessionId=null
31-Oct-2023 17:44:40.465 INFO [http-nio-8080-exec-4] org.apache.catalina.filters.RequestDumperFilter.doLog http-nio-8080-exec-4 scheme=http
31-Oct-2023 17:44:40.465 INFO [http-nio-8080-exec-4] org.apache.catalina.filters.RequestDumperFilter.doLog http-nio-8080-exec-4 serverName=10.51.16.5
31-Oct-2023 17:44:40.465 INFO [http-nio-8080-exec-4] org.apache.catalina.filters.RequestDumperFilter.doLog http-nio-8080-exec-4 serverPort=80
31-Oct-2023 17:44:40.466 INFO [http-nio-8080-exec-4] org.apache.catalina.filters.RequestDumperFilter.doLog http-nio-8080-exec-4 servletPath=/accountMessageTemplate/queryAccountMessageTemplateList
31-Oct-2023 17:44:40.466 INFO [http-nio-8080-exec-4] org.apache.catalina.filters.RequestDumperFilter.doLog http-nio-8080-exec-4 isSecure=false
二、设置打印到独立的日志文件
修改 CATALINA_BASE/conf/logging.properties
,创建日志文件
############################################################
# Request Dumper Filter, extral log
############################################################
# To this configuration below, 1request-dumper.org.apache.juli.FileHandler
# also needs to be added to the handlers property near the top of the file
1request-dumper.org.apache.juli.FileHandler.level = INFO
1request-dumper.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
1request-dumper.org.apache.juli.FileHandler.prefix = request-dumper.
1request-dumper.org.apache.juli.FileHandler.encoding = UTF-8
1request-dumper.org.apache.juli.FileHandler.formatter = org.apache.juli.VerbatimFormatter
org.apache.catalina.filters.RequestDumperFilter.level = INFO
org.apache.catalina.filters.RequestDumperFilter.handlers = \
1request-dumper.org.apache.juli.FileHandler
注意
要把1request-dumper.org.apache.juli.FileHandler
添加到文件上部的 handlers。
如下:
handlers = 1catalina.org.apache.juli.AsyncFileHandler, 2localhost.org.apache.juli.AsyncFileHandler, 3manager.org.apache.juli.AsyncFileHandler, 4host-manager.org.apache.juli.AsyncFileHandler, java.util.logging.ConsoleHandler, 1request-dumper.org.apache.juli.FileHandler
然后,就出现了独立的日志文件
[admin@VM-16-5-centos apache-tomcat-9.0.69]$ ll logs/
total 52
-rw-r----- 1 admin admin 6088 Oct 31 20:43 catalina.2023-10-31.log
prw-r----- 1 admin admin 0 Oct 31 20:43 catalina.out
-rw-r----- 1 admin admin 37906 Oct 31 20:43 catalina.out.2023-10-31.log
-rw-r----- 1 admin admin 0 Oct 31 20:43 host-manager.2023-10-31.log
-rw-r----- 1 admin admin 815 Oct 31 20:43 localhost.2023-10-31.log
-rw-r----- 1 admin admin 0 Oct 31 20:43 localhost_access_log.2023-10-31.txt
-rw-r----- 1 admin admin 0 Oct 31 20:43 manager.2023-10-31.log
-rw-r----- 1 admin admin 0 Oct 31 20:43 request-dumper.2023-10-31.log
网友评论