1. 程式人生 > >設定feign配置日誌級別

設定feign配置日誌級別

設定feign配置日誌級別

基於《<spring-cloud.version>Greenwich.RC2</spring-cloud.version>》

根據spring cloud文件: https://cloud.spring.io/spring-cloud-static/Greenwich.RC2/single/spring-cloud.html#_feign_logging

feign日誌

在建立feign client的時候,就建立了logger, 預設logger的名稱是建立feign client的服務介面類的全路徑,通俗的來講就是加了@FeignClient

介面類的全路徑

首先在application.yml檔案中指定日誌級別:

logging:
  level:
    com.**.api.service.IFeignService: DEBUG

設定日誌記錄的級別

logger有四種類型:NONE,BASIC,HEADERS, FULL,通過註冊Bean來設定日誌記錄級別:

@Configuration
public class LogConfiguration {

    @Bean
    Logger.Level feignLoggerLevel(){
        return Logger.Level.FULL;
} }

在feign client加上:

@FeignClient(name = "IFeignService", configuration = LogConfiguration.class)
public interface IFeignService {

    @RequestMapping(value = "/index", method = RequestMethod.GET)
    public String invokeSayHi();

}

日誌記錄結果:

2018-12-31    c.g.v.f.c.api.service.IFeignService  <--- HTTP/1.1 200 (462ms)
2018-12-31    c.g.v.f.c.api.service.IFeignService  content-length: 5
2018-12-31    c.g.v.f.c.api.service.IFeignService  content-type: text/plain;charset=UTF-8
2018-12-31    c.g.v.f.c.api.service.IFeignService  date: Mon, 31 Dec 2018 13:35:48 GMT
2018-12-31    c.g.v.f.c.api.service.IFeignService 
2018-12-31    c.g.v.f.c.api.service.IFeignService  index
2018-12-31    c.g.v.f.c.api.service.IFeignService  <--- END HTTP (5-byte body)