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

后端 未结 5 722
萌比男神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:30

    JohanB's solution works, but if you don't want to write code, someone did it better and wrapped Server access logs in a nice Spring Boot starter. It covers Tomcat, Jetty and Undertow.

    Just add the dependency :

    
        net.rakugakibox.spring.boot
        logback-access-spring-boot-starter
        2.7.1
    
    

    And a logback-access.xml file at the classpath root :

    
        
            
                common
            
        
        
    
    

    and the access logs are printed to stdout :

    127.0.0.1 - - [08/févr./2019:11:23:30 +0100] "GET /password HTTP/1.1" 200 32
    

    At this point you will need to create the TeeFilter Bean on your own if you want to print the full HTTP request & response for debugging.

提交回复
热议问题