2

I want to build a simple Spring Web Client who send message from stdin but the WebClient show all debug informations on stdout.

How to disable the logs generated by Webclient ?

Code of the client

WebClient webclient = WebClient.builder().baseUrl("http://localhost:8080/").build();
webClient.post().uri(uriBuilder -> uriBuilder.path("/test").queryParam("id",1).build()).retrieve().bodyToMono(Log.class).block();
Ryoh
  • 37
  • 1
  • 6

2 Answers2

2

WebClient uses the standard HTTPClient to work, and when initialized, it connects the SLF4J facade for logging. Facade iterates over several frameworks known to it, looking for the one set in the Classpath.

Spring WebClent installs Logback as a dependency.

SLF4J starts working through Logback, and can be configured using the logback.xml configuration file

<configuration>
    <root level="OFF">
    </root>
</configuration>
0

you can customize your logs as you want. as the image you mention,
Go to the application.properties put logger values to disable as OFF [io.netty]

logging.level.io.netty=off

do you want to fully disable all logs from your project, disable root below.

logging.level.root=off
Mafei
  • 3,063
  • 2
  • 15
  • 37
  • Unfortunately, it doesn't work for me. Maybe it's because I'm directly using a webclient in a main without using springbootaplication? I will edit my post to show the client code. – Ryoh Dec 28 '20 at 18:32
  • Please try out with this ```logging.level.reactor.netty.http.client=OFF``` – Mafei Dec 28 '20 at 18:38
  • and refer this https://stackoverflow.com/questions/46154994/how-to-log-spring-5-webclient-call – Mafei Dec 28 '20 at 18:40
  • Ok, it work but only if i use @SpringBootApplication and SpringApplication.run(testClient.class, args); Do you think there is an alternative without that? Thanks for your help – Ryoh Dec 28 '20 at 18:45
  • I'm not familiar much with spring web client bro. anyway please refer this too https://stackoverflow.com/questions/46154994/how-to-log-spring-5-webclient-call – Mafei Dec 28 '20 at 18:50