1. 程式人生 > >使用Spring Cloud Feign 日誌查看請求響應

使用Spring Cloud Feign 日誌查看請求響應

ati level prop image img 調用 yml 文件 logger

在使用微服務時,常常會用feign做客戶端去調用別的微服務,但是在日誌中很難查看到具體的請求和響應。因此,需要把feign默認的日誌打開。

日誌設置

  • 創建feign配置類

@Configuration
public class FeignLogConfiguration {

    @Bean
    Logger.Level feignLoggerLevel() {

        return Logger.Level.FULL;

    }
}
  • 其中Logger.Level是枚舉類

技術分享圖片

  • application.properties或者application.yml文件中設置Feign客戶端的日誌級別----->可以看到feign客戶端的請求響應
logging.level.com.wugui.spring.cloud.weather.Service:debug

  • 其中com.wugui.spring.cloud.weather.Service為feign client接口所在包

技術分享圖片

日誌查看

技術分享圖片

使用Spring Cloud Feign 日誌查看請求響應