How to log all headers of request/response in Tomcat 7

tomcat log request body
tomcat request logging
tomcat access log format
tomcat access log query string
tomcat access log to stdout
tomcat log response body
tomcat access log parser
tomcat response header filter

I'm trying to log all headers of request/response in Tomcat 7. I tried to use access-log-valve. But as mentioned in the link, we can print headers only one by one. We have to specify each and every header we need.

e.g.

pattern="%{User-Agent}i %{Content-Type}i %{Accept}i %{Accept-Encoding}i
%{Accept-Language}i %{Accept-Charset}i %r %h %q"

Isn't there a way to log all headers at once, may be using a wildcard?

Thanks.

There's no way out of the box - but an easy alternative is to stuff run a filter. The filter shove's all the headers you want into the servlet request. Then use "%{foo}r" in your pattern where foo is the name of the variable in the servlet request.

Log all HTTP requests of Tomcat Server?, To enable http level request/response logs in Application Server (AS), we can use the Access_Log_Valve which is provided in Tomcat 7. Content-type, Accept and Accept-encoding headers of every request coming to AS. I'm trying to log all headers of request/response in Tomcat 7. I tried to use access-log-valve. But as mentioned in the link, we can print headers only one by one. We have to specify each and every

Enabling HTTP Level Request/Response Logs, Some requests may be handled by Tomcat before they are passed to a container. The Extended Access Log Valve supports all configuration attributes x-O( XXX) for a concatenation of all outgoing response headers with� JFrog Support 2017-02-06 13:21 Tomcat supports the creation of custom access log formats out-of-the-box. For example, one may need to log the value of a custom HTTP header.

David Lee says add this to your server.xml:

<Valve className="org.apache.catalina.valves.RequestDumperValve"/>

AccessLogValve (Apache Tomcat 7.0.104 API Documentation), AccessLogValve" directory="logs" prefix="custom-log" suffix=".log" pattern="%t % U %{X-Custom-Header}i"/>. 3.Restart the Artifactory server for� Before rolling up your own solution, take a look at the valve component that Tomcat supports. In particular, the aptly named RequestDumperValve will log all the request and response headers in Tomcat. To enable the valve, just go to your server.xml file in the /conf directory and uncomment this line: Then restart your server and the headers will appear in your log file.

Add this to your web.xml:

<filter>
    <filter-name>Request Dumper Filter</filter-name>
    <filter-class>org.apache.catalina.filters.RequestDumperFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>Request Dumper Filter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

This will log request and response headers in cataline.out log file:

==> /usr/local/tomcat/logs/catalina.out <==
2020-06-10 12:20:47.844 INFO  [RequestDumperFilter] - http-nio-8080-exec-9 START TIME        =10-Jun-2020 12:20:47
2020-06-10 12:20:47.845 INFO  [RequestDumperFilter] - http-nio-8080-exec-9         requestURI=/myservice/health
2020-06-10 12:20:47.845 INFO  [RequestDumperFilter] - http-nio-8080-exec-9           authType=null
2020-06-10 12:20:47.846 INFO  [RequestDumperFilter] - http-nio-8080-exec-9  characterEncoding=null
2020-06-10 12:20:47.846 INFO  [RequestDumperFilter] - http-nio-8080-exec-9      contentLength=-1
2020-06-10 12:20:47.847 INFO  [RequestDumperFilter] - http-nio-8080-exec-9        contentType=null
2020-06-10 12:20:47.847 INFO  [RequestDumperFilter] - http-nio-8080-exec-9        contextPath=/myservice
2020-06-10 12:20:47.848 INFO  [RequestDumperFilter] - http-nio-8080-exec-9             header=host=192.168.99.200:9080
2020-06-10 12:20:47.849 INFO  [RequestDumperFilter] - http-nio-8080-exec-9             header=accept=text/plain, text/*, */*
2020-06-10 12:20:47.849 INFO  [RequestDumperFilter] - http-nio-8080-exec-9             header=accept-encoding=gzip
2020-06-10 12:20:47.850 INFO  [RequestDumperFilter] - http-nio-8080-exec-9             header=connection=close
2020-06-10 12:20:47.850 INFO  [RequestDumperFilter] - http-nio-8080-exec-9             locale=en_US
2020-06-10 12:20:47.851 INFO  [RequestDumperFilter] - http-nio-8080-exec-9             method=GET
2020-06-10 12:20:47.851 INFO  [RequestDumperFilter] - http-nio-8080-exec-9           pathInfo=null
2020-06-10 12:20:47.851 INFO  [RequestDumperFilter] - http-nio-8080-exec-9           protocol=HTTP/1.1
2020-06-10 12:20:47.852 INFO  [RequestDumperFilter] - http-nio-8080-exec-9        queryString=null
2020-06-10 12:20:47.852 INFO  [RequestDumperFilter] - http-nio-8080-exec-9         remoteAddr=172.18.0.1
2020-06-10 12:20:47.853 INFO  [RequestDumperFilter] - http-nio-8080-exec-9         remoteHost=172.18.0.1
2020-06-10 12:20:47.853 INFO  [RequestDumperFilter] - http-nio-8080-exec-9 requestedSessionId=null
2020-06-10 12:20:47.854 INFO  [RequestDumperFilter] - http-nio-8080-exec-9             scheme=https
2020-06-10 12:20:47.854 INFO  [RequestDumperFilter] - http-nio-8080-exec-9         serverName=192.168.99.200
2020-06-10 12:20:47.855 INFO  [RequestDumperFilter] - http-nio-8080-exec-9         serverPort=443
2020-06-10 12:20:47.855 INFO  [RequestDumperFilter] - http-nio-8080-exec-9        servletPath=/health
2020-06-10 12:20:47.856 INFO  [RequestDumperFilter] - http-nio-8080-exec-9           isSecure=true
2020-06-10 12:20:47.856 INFO  [RequestDumperFilter] - http-nio-8080-exec-9 ------------------=--------------------------------------------
2020-06-10 12:20:47.857 INFO  [RequestDumperFilter] - http-nio-8080-exec-9 ------------------=--------------------------------------------
2020-06-10 12:20:47.857 INFO  [RequestDumperFilter] - http-nio-8080-exec-9           authType=null
2020-06-10 12:20:47.857 INFO  [RequestDumperFilter] - http-nio-8080-exec-9        contentType=application/json;charset=UTF-8
2020-06-10 12:20:47.858 INFO  [RequestDumperFilter] - http-nio-8080-exec-9             status=200
2020-06-10 12:20:47.858 INFO  [RequestDumperFilter] - http-nio-8080-exec-9 END TIME          =10-Jun-2020 12:20:47
2020-06-10 12:20:47.858 INFO  [RequestDumperFilter] - http-nio-8080-exec-9 ===============================================================

Tested on Tomcat 8 on Centos 7.

Apache Tomcat 7 Configuration Reference (7.0.104), requestdumpervalve. Is it possible to print all requests to Tomcat and responses from Tomcat in a logfile? ex: request. headers: [header1=a, header2=a]. The common log format is ok but changing the pattern to combined adds the User-Agent (browser or robot type) and the referring web site and URI. Tomcat also provides additional options to log things like the request protocol, the local port that received the request, user session ID's, incoming or outgoing request headers, etc.

How can I log custom request headers using the Tomcat Access Log , Logging request and response headers in Tomcat 7. Logging request and response headers in Tomcat 7. <filter>. <filter-name>requestdumper</filter-name >. To enable http level request/response logs in WSO2AS, we can use Access_Log_Valve which is provided in Tomcat 7. To enable logging, you have to put following xml element under /Server/Service/Engine/Host/ element in {WSO2AS_HOME}/repository/conf/tomcat/catalina-server.xml, and restart the AS server.

Log all HTTP requests of Tomcat Server?, It is modeled after the Apache HTTP Server log configuration syntax: %{xxx}i for incoming headers; %{xxx}o for outgoing response headers; %{xxx}c write local port on which this request was received - %p If null, every request is logged. Hi guys, I have a requirement to monitor http request/response logs. We have a embedded Tomcat 7. Could you please point out the options available to do this?. I'm already aware of the Access Log Valve [1]. But it can only log separate request headers and query params of the request body.. Would like to know if there is any better approach..

Logging request and response headers in Tomcat 7 � GitHub, Enabling the Tomcat Access Logger. Tomcat access logging is enabled by modifying the server.xml file and Remote authenticated user ID (if one exists); Date and Time of the request; HTTP Method and URI requested; HTTP Response Status Code; Size, in bytes, of the response (excluding http response headers). As you did write correctly, the code for logging a specific header is %{foobar}i where foobar is the name of the header. So, the only solution is to create a specific format string. When you expect a non-standard header like x-my-nonstandard-header, then use %{x-my-nonstandard-header}i. If your server is going to ignore this non-standard-header, why should you want to write it to your logfile?

Comments
  • there is - maybe was not back then - see other answers
  • RequestDumperValue is not available in Tomcat 7: Tomcat 7 Valves