how to log Spring 5 WebClient call

前端 未结 8 831
清酒与你
清酒与你 2020-11-29 03:13

I\'m trying to log a request using Spring 5 WebClient. Do you have any idea how could I achieve that?

(I\'m using Spring 5 and Spring boot 2)

The code looks

8条回答
  •  孤城傲影
    2020-11-29 03:21

    If you don't want to log the body, then this is really easy.

    Spring Boot >= 2.1.0

    Add the following to application.properties:

    logging.level.org.springframework.web.reactive.function.client.ExchangeFunctions=TRACE
    spring.http.log-request-details=true
    

    The second line causes headers to be included in the log.

    Spring Boot < 2.1.0

    Add the following to application.properties:

    logging.level.org.springframework.web.reactive.function.client.ExchangeFunctions=TRACE
    

    Instead of the second line above, you need to declare a class like this:

    @Configuration
    static class LoggingCodecConfig {
    
        @Bean
        @Order(0)
        public CodecCustomizer loggingCodecCustomizer() {
            return (configurer) -> configurer.defaultCodecs()
                    .enableLoggingRequestDetails(true);
        }
    
    }
    

    Courtesy of this Brian Clozel answer

提交回复
热议问题