0

I have a Spring Boot 2.7.2 web application. The Tomcat access log properties are defined as

server.tomcat.accesslog.enabled=TRUE
server.tomcat.accesslog.directory=log
server.tomcat.accesslog.pattern=%h %l %u [%t] "%r" %s %b "%{Referer}i" "%{User-Agent}i" %D [%I] "%{Host}i"

I'm not using any logback configuration files (like logback.xml or logback-spring.xml).

Locally, when using embedded Tomcat, the access logs are logged as configured. However, when I deploy the application to an external Tomcat, the used access log pattern seems to be a default pattern with less information and looks like this:

%h %l %u [%t] "%r" %s %b

How can I configure the access log pattern in a way that it works for embedded and external Tomcat?

1 Answers1

0

A Spring Boot application can configure the embedded Tomcat regarding the access log pattern, but it can't configure the access log pattern of a standalone Tomcat it is deployed to.

In order to apply a custom access log pattern, you need to edit Tomcat's conf/server.xml file and need to adapt the existing AccessLogValve configuration, like this (relevant is the pattern attribute):

<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
       prefix="localhost_access_log" suffix=".txt"
       pattern="%h %l %u %t &quot;%r&quot; %s %b &quot;%{Referer}i&quot; &quot;%{User-Agent}i&quot; %D [%I] &quot;%{Host}i&quot;" />

Afterwards you need to restart Tomcat to apply this change. The access log files should then include the additional information of each request.

Note that this change affects the access logging of all applications deployed to the standalone Tomcat.