how to log Spring 5 WebClient call

前端 未结 8 832
清酒与你
清酒与你 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:30

    You can have netty do logging of the request/responses with by asking it todo wiretaping, if you create your Spring WebClient like this then it enables the wiretap option.

            WebClient webClient = WebClient.builder()
                .clientConnector(new ReactorClientHttpConnector(
                    HttpClient.create().wiretap(true)
                ))
                .build()
    

    and then have your logging setup:

    logging.level.reactor.netty.http.client.HttpClient: DEBUG
    

    this will log everything for the request/response (including bodies), but the format is not specific to HTTP so not very readable.

提交回复
热议问题