我如何在 java webclient 中获取日志消息?

问题描述

我是 Spring 框架的初学者。

我想进行日志记录或其他程序。 但我什么也没收到。

帮我做什么。

public class WebClientRunner implements ApplicationRunner {
  
   private final WebClient.Builder webClientBuilder;

   @Override
   public void run(ApplicationArguments args) {
      long startTme = System.currentTimeMillis();

      WebClient webClient = webClientBuilder.build();

      Mono<ResponseEntity> result = webClient.post()
             .uri("http://192.168.7.158:18080/test")   //this contoller is return 200 ok.
             .body(BodyInserters.FormInserter("parameter","ABCDEFGHIGHT"))
             .retrieve()
             .bodyToMono(ResponseEntity.class);

      result.subscribe( ret -> {

           //This part does not work
           //The actual post is sent....but no logging anything.
           log.info("time {} {} {}",System.currentTimeMillis() - startTme,ret.getStatusCode(),ret.getStatusCodeValue());
             });
           ////////////////////////////////////////////////////
        }

}

我想记录订阅的返回值。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)