You have to configure the tomcat container in spring boot manually like this
You have to create the bean of EmbeddedServletContainerFactory and configure the log in tomcat container , below are the sample code (I am not tested it , but it may be run).
The tomcat now search the logback-access.xml file in classpath automatically the configure the logging
For Spring boot version < 2.0.0
@SpringBootApplication
public class ABCApplication {
@Bean
public EmbeddedServletContainerFactory servletContainer() {
TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory();
LogbackValve logbackValve = new LogbackValve();
logbackValve.setFilename("logback-access.xml");
tomcat.addContextValves(logbackValve);
return tomcat;
}
public static void main(String[] args) {
SpringApplication.run(ABCApplication.class, args);
}
}
The EmbeddedServletContainerFactory is replace by TomcatServletWebServerFactory is spring boot version 2.0.0 , so use required factory to configure the tomacat.
Now you can provide your logback-access.xml like this
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%h %l %u %t "%r" %s %b</pattern>
</encoder>
</appender>
<appender-ref ref="STDOUT" />
</configuration>
You can add the appender to xml to log the tomcat logging in file.
You have to look about LogbackValve
You have to add the following dependency for the LogbackValve
<dependency>
<groupId>net.rakugakibox.spring.boot</groupId>
<artifactId>logback-access-spring-boot-starter</artifactId>
</dependency>
Hope it may be help jagamot !