How can I log custom request headers using the Tomcat Access Log Valve?

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. Here is how this can be achieved in 3 simple steps:

1.Open the $ARTIFACTORY_HOME/tomcat/conf/server.xml file

2.Add an additional Access Log Valve below the existing one, like this:

Here's the Valve text seen in the above screenshot:
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="custom-log" suffix=".log" pattern="%t %U %{X-Custom-Header}i"/>



3.Restart the Artifactory server for the changes to take effect. 


You are done. The 'pattern' attribute can of course be customised according to your needs by using the various Identifiers documented here


To find out whether our new log is logging our custom header, we can make a request such as:


curl http://localhost:8081/artifactory/api/system/ping -uadmin:password -H "X-Custom-Header: some-value"


And monitor the $ARTIFACTORY_HOME/tomcat/logs/custom-log.<DATE>.log file. Here's how our line should look like:


[19/Jun/2016:10:15:08 +0300] /artifactory/api/system/ping some-value