Reputation: 21
I am working with Spring WebClient and exploring ways to enable detailed logging for debugging purposes. Specifically, I am looking at two approaches: ExchangeStrategies and wiretap. Below are the details of my configuration:
Using wiretap for logging.
I have configured the WebClient to use Netty's wiretap feature to log network-level data for HTTP requests and responses:
HttpClient httpClient = HttpClient.create()
.wiretap("reactor.netty.http.client.HttpClient", LogLevel.DEBUG, AdvancedByteBufFormat.TEXTUAL);
WebClient webClient = WebClient.builder()
.clientConnector(new ReactorClientHttpConnector(httpClient))
.build();
This logs details such as headers, request body, response body, and HTTP status codes at the network level.
Using ExchangeStrategies for logging.
Additionally, I enabled logging for the serialization/deserialization process by customizing the ExchangeStrategies:
ExchangeStrategies strategies = ExchangeStrategies.builder()
.codecs(configurer -> configurer.defaultCodecs().maxInMemorySize(1024 * 1024 * 50))
.build();
strategies.messageWriters().stream()
.filter(LoggingCodecSupport.class::isInstance)
.forEach(writer -> ((LoggingCodecSupport) writer).setEnableLoggingRequestDetails(true));
This approach focuses on logging details during the transformation of request and response bodies into objects.
My questions:
Environment:
Spring Boot: 3.3.2
Spring WebFlux: 3.3.2
Reactor Netty: 1.2.6
JDK: 17
Upvotes: 0
Views: 15