How do you tell Spring Boot to send the embedded Tomcat's access logs to stdout?

后端 未结 5 689
萌比男神i
萌比男神i 2020-12-28 08:47

In a standalone Spring Boot web application (executable jar), how do you tell Spring Boot that we want the embedded Tomcat instance\'s HTTP access logs to be sent to stdout?

5条回答
  •  自闭症患者
    2020-12-28 09:23

    Here's the followup up on the great answer from JohanB, for Spring Boot 2.0.0+.

    In Spring Boot 2.0.0, the EmbeddedServletContainerFactory was replaced with TomcatServletWebServerFactory. All other aspects of JohanB's answer still works correctly the factory bean creation just needs to be modified:

    @Bean
    public TomcatServletWebServerFactory servletContainer() {
        TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
        // put logback-access.xml in src/main/resources/conf
        tomcat.addContextValves(new LogbackValve());
        return tomcat;
    }
    

提交回复
热议问题