初始重要提示,尤其是对于生产环境:小心启用过滤器,因为它可能会损害您的请求参数编码!所以也许一定要先设置org.apache.catalina.filters.SetCharacterEncodingFilter来正确设置一切!
从Tomcat 7 +开始,您应该通过过滤器进行操作:
<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>
然后将其记录到例如这样的一些特殊日志文件中CATALINA_BASE/conf/logging.properties
(基于Tomcat 7 文档修改):
## this may likely be your (to-be-updated) orig handlers declaration:
#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
## ... and you have to add your 1request-dumper:
handlers = \
1request-dumper.org.apache.juli.FileHandler\
,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
## ...
# 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 = localhost_access_log.req-dumps.
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
直到Tomcat 6之前,你可以使用RequestDumperValve
(如布赖恩的回答):
将此添加到您的server.xml
:
<Valve className="org.apache.catalina.valves.RequestDumperValve"/>