Feign提供了日志打印功能,我们可以通过配置来调整日志级别,从而了解Feign中Http请求的细节。

说白了就是对Feign接口的调用情况进行监控和输出

OpenFeign日志打印功能:

1、日志级别

NONE: 默认的,不显示任何日志;
BASIC:仅记录请求方法、URL、响应状态码及执行时间
HEADERS:除了BASIC中定义的信息之外还有请求和响应的头信息
FULL:除了HEADERS中定义的信息之外,还有请求和响应的正文及元数据

2、配置日志bean

image.png

  1. @Configuration
  2. public class FeignConfig {
  3. @Bean
  4. feign.Logger.Level feignLoggerLevel()
  5. {
  6. return Logger.Level.FULL;
  7. }
  8. }

3、YML文件里需要开启日志的Feign客户端

  1. logging:
  2. level:
  3. # feign日志以什么级别监控哪个接口
  4. com.atguigu.springcloud.service.PaymentFeignService: debug

4、后台日志查看

http://localhost/consumer/payment/get/1

  1. ]}ServerList:org.springframework.cloud.netflix.ribbon.eureka.DomainExtractingServerList@3e5f28b6
  2. 2021-05-31 10:12:43.790 DEBUG 548 --- [p-nio-80-exec-1] c.a.s.service.PaymentFeignService : [PaymentFeignService#getPaymentById] <--- HTTP/1.1 200 (341ms)
  3. 2021-05-31 10:12:43.791 DEBUG 548 --- [p-nio-80-exec-1] c.a.s.service.PaymentFeignService : [PaymentFeignService#getPaymentById] connection: keep-alive
  4. 2021-05-31 10:12:43.791 DEBUG 548 --- [p-nio-80-exec-1] c.a.s.service.PaymentFeignService : [PaymentFeignService#getPaymentById] content-type: application/json
  5. 2021-05-31 10:12:43.791 DEBUG 548 --- [p-nio-80-exec-1] c.a.s.service.PaymentFeignService : [PaymentFeignService#getPaymentById] date: Mon, 31 May 2021 02:12:43 GMT
  6. 2021-05-31 10:12:43.791 DEBUG 548 --- [p-nio-80-exec-1] c.a.s.service.PaymentFeignService : [PaymentFeignService#getPaymentById] keep-alive: timeout=60
  7. 2021-05-31 10:12:43.791 DEBUG 548 --- [p-nio-80-exec-1] c.a.s.service.PaymentFeignService : [PaymentFeignService#getPaymentById] transfer-encoding: chunked
  8. 2021-05-31 10:12:43.791 DEBUG 548 --- [p-nio-80-exec-1] c.a.s.service.PaymentFeignService : [PaymentFeignService#getPaymentById]
  9. 2021-05-31 10:12:43.793 DEBUG 548 --- [p-nio-80-exec-1] c.a.s.service.PaymentFeignService : [PaymentFeignService#getPaymentById] {"code":200,"message":"插入数据库成功","data":{"id":1,"serial":"zxd"}}
  10. 2021-05-31 10:12:43.794 DEBUG 548 --- [p-nio-80-exec-1] c.a.s.service.PaymentFeignService : [PaymentFeignService#getPaymentById] <--- END HTTP (77-byte body)
  11. 2021-05-31 10:12:44.635 INFO 548 --- [erListUpdater-0] c.netflix.config.ChainedDynamicProperty : Flipping property: CLOUD-PAYMENT-SERVICE.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647