当前位置:  开发笔记 > 编程语言 > 正文

记录Tomcat服务器的所有HTTP请求?

如何解决《记录Tomcat服务器的所有HTTP请求?》经验,为你挑选了1个好方法。

是否可以在日志文件中打印所有对Tomcat的请求和Tomcat的响应?

例如:

请求

标题:[header1 = a,header2 = a]

参数:[param1 = avv,param2 = b]

响应

status-code = 200

响应=它的作品

Richard Osse.. 15

把一个AccessLogValveHostContext元素如:



    

 

pattern属性可以使用两个速记值(常用,组合)中的一个或使用多个常量和替换字符串的自定义模式.让我引用Tomcat文档:

https://tomcat.apache.org/tomcat-8.0-doc/config/valve.html#Access_Log_Valve

pattern属性的值由文字文本字符串组成,与前缀为"%"字符的模式标识符组合,以替换当前请求和响应中的相应变量值.支持以下模式代码:

%a - Remote IP address
%A - Local IP address
%b - Bytes sent, excluding HTTP headers, or '-' if zero
%B - Bytes sent, excluding HTTP headers
%h - Remote host name (or IP address if enableLookups for the connector is false)
%H - Request protocol
%l - Remote logical username from identd (always returns '-')
%m - Request method (GET, POST, etc.)
%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)
%s - HTTP status code of the response
%S - User session ID
%t - Date and time, in Common Log Format
%u - Remote user that was authenticated (if any), else '-'
%U - Requested URL path
%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)

还支持写入信息传入或传出标头,cookie,会话或请求属性以及特殊时间戳格式.它以Apache HTTP Server日志配置语法为模型.它们中的每一个都可以使用不同的xxx键多次使用:

%{xxx}i write value of incoming header with name xxx
%{xxx}o write value of outgoing header with name xxx
%{xxx}c write value of cookie with name xxx
%{xxx}r write value of ServletRequest attribute with name xxx
%{xxx}s write value of HttpSession attribute with name xxx
%{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 pattern xxx

正如您所看到的,可以使用很多字段,但如果您还需要更多字段,则必须编写自己的AccessLogValve实现.



1> Richard Osse..:

把一个AccessLogValveHostContext元素如:



    

 

pattern属性可以使用两个速记值(常用,组合)中的一个或使用多个常量和替换字符串的自定义模式.让我引用Tomcat文档:

https://tomcat.apache.org/tomcat-8.0-doc/config/valve.html#Access_Log_Valve

pattern属性的值由文字文本字符串组成,与前缀为"%"字符的模式标识符组合,以替换当前请求和响应中的相应变量值.支持以下模式代码:

%a - Remote IP address
%A - Local IP address
%b - Bytes sent, excluding HTTP headers, or '-' if zero
%B - Bytes sent, excluding HTTP headers
%h - Remote host name (or IP address if enableLookups for the connector is false)
%H - Request protocol
%l - Remote logical username from identd (always returns '-')
%m - Request method (GET, POST, etc.)
%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)
%s - HTTP status code of the response
%S - User session ID
%t - Date and time, in Common Log Format
%u - Remote user that was authenticated (if any), else '-'
%U - Requested URL path
%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)

还支持写入信息传入或传出标头,cookie,会话或请求属性以及特殊时间戳格式.它以Apache HTTP Server日志配置语法为模型.它们中的每一个都可以使用不同的xxx键多次使用:

%{xxx}i write value of incoming header with name xxx
%{xxx}o write value of outgoing header with name xxx
%{xxx}c write value of cookie with name xxx
%{xxx}r write value of ServletRequest attribute with name xxx
%{xxx}s write value of HttpSession attribute with name xxx
%{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 pattern xxx

正如您所看到的,可以使用很多字段,但如果您还需要更多字段,则必须编写自己的AccessLogValve实现.


不支持记录*all*标题?(这基本上是问题)
推荐阅读
小色米虫_524
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有