设置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)