栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

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

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

把一个

AccessLogValve
Host
Context
元素如:

<Host name="www.mysite.com" appbase="..." >    <Valve className="org.apache.catalina.valves.AccessLogValve"     directory="logs" prefix="mysitelog." suffix=".txt"      pattern="..." resolveHosts="false" /></Host>

pattern
属性可以采用两个速记值之一( commoncombined
)或使用多个常量和替换字符串的自定义模式。让我引用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 pre 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
实现。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/435762.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号