设置feign配置日志级别

2022年11月13日12:55:40

设置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来设置日志记录级别:

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

在feign client加上:

@FeignClient(name="IFeignService", configuration= LogConfiguration.class)publicinterfaceIFeignService{@RequestMapping(value="/index", method= RequestMethod.GET)public StringinvokeSayHi();}

日志记录结果:

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)
  • 作者:iiaythi
  • 原文链接:https://blog.csdn.net/u013887008/article/details/85489631
    更新时间:2022年11月13日12:55:40 ,共 1187 字。