Spring Webflux Webclient: Issue with wiretap logging
Asked Answered
K

2

8

Quick question regarding Java Spring Webflux WebClient and the wiretap logging please.

I am currently using Java with SpringBoot Webflux WebClient 2.5.0 to make outbound http requests (where I am the source), I need to make a http request (to a target).

I make the outbound http client like this:

webClientUtil.getWebClient().mutate().baseUrl(someUrl).build().post().body(BodyInserters.fromValue(someRequest)).exchangeToMono(clientResponse -> clientResponse.bodyToMono(SomeResponse.class));

I would like to log the request and the response, hence, I am coding the following:

final HttpClient httpClient = HttpClient.create().wiretap("reactor.netty.http.client.HttpClient", LogLevel.INFO, AdvancedByteBufFormat.HEX_DUMP)

inside a Util class:

public WebClient getWebClient() {
        final HttpClient httpClient = HttpClient.create().wiretap("reactor.netty.http.client.HttpClient", LogLevel.INFO, AdvancedByteBufFormat.HEX_DUMP).metrics(true, Function.identity()).proxy(proxy -> proxy.type(ProxyProvider.Proxy.HTTP).host(proxyUrl));
        return WebClient.create().mutate().defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE, HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE).clientConnector(new ReactorClientHttpConnector(httpClient)).build();
    }

(The WebClient implantation has been tested and working)

And I have my logging level set to INFO with logging.level.root=INFO

Please note the log level is info, the wiretap is also info.

Unfortunately, I am not seeing any extra logs.

What am I doing wrong please?

Thank you!

Kessel answered 24/5, 2021 at 10:31 Comment(4)
Are you subscribing to the request or passing the the response back to something that subscribes? Here's a working example that is effectively the same as your config, github.com/DarrenForsythe/so67670516 if you run the app it'll dump the request as expected. I'm wondering if the requests are happening/being subscribed to or another configuration/logging confg is affecting itGoosegog
Thanks for the comment! Yes, I am subscribing to it, doing computations fine on the response etc. The only issue is that I am not seeing any of the wiretap logsKessel
logging.level.reactor.netty.http.client.HttpClient = INFO Have you tried setting the logging level specifically for the package?Ial
Yes, both will not yield any extra logsKessel
P
1

in webclient, you need to add Log Level to DEBUG, instead of INFO

final HttpClient httpClient = HttpClient.create().wiretap("reactor.netty.http.client.HttpClient", LogLevel.DEBUG, AdvancedByteBufFormat.HEX_DUMP)

Next, you need to set log level for the httpclient package

logging.level.reactor.netty.http.client=DEBUG

With this you should be able to see the logs

You can refer this baeldung article for more info

Pulpy answered 2/5, 2024 at 7:25 Comment(0)
S
0

any logback.xml file somewhere that would override the config ?

I had similar problem in some tests, and solved it by having this in my logback-test.xml :

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <include resource="org/springframework/boot/logging/logback/base.xml" />

  <logger name="reactor.netty" level="debug"/>

</configuration> 
Superconductivity answered 9/6, 2022 at 14:33 Comment(1)
logback-test.xml and not logback-text.xmlNe

© 2022 - 2025 — McMap. All rights reserved.