Feign提供了日志打印功能,我们可以通过配置来调整日志级别,从而了解Feign中Http请求的细节。
说白了就是对Feign接口的调用情况进行监控和输出
OpenFeign日志打印功能:
1、日志级别
NONE: 默认的,不显示任何日志;
BASIC:仅记录请求方法、URL、响应状态码及执行时间
HEADERS:除了BASIC中定义的信息之外还有请求和响应的头信息
FULL:除了HEADERS中定义的信息之外,还有请求和响应的正文及元数据
2、配置日志bean
@Configuration
public class FeignConfig {
@Bean
feign.Logger.Level feignLoggerLevel()
{
return Logger.Level.FULL;
}
}
3、YML文件里需要开启日志的Feign客户端
logging:
level:
# feign日志以什么级别监控哪个接口
com.atguigu.springcloud.service.PaymentFeignService: debug
4、后台日志查看
http://localhost/consumer/payment/get/1
]}ServerList:org.springframework.cloud.netflix.ribbon.eureka.DomainExtractingServerList@3e5f28b6
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)
2021-05-31 10:12:43.791 DEBUG 548 --- [p-nio-80-exec-1] c.a.s.service.PaymentFeignService : [PaymentFeignService#getPaymentById] connection: keep-alive
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
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
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
2021-05-31 10:12:43.791 DEBUG 548 --- [p-nio-80-exec-1] c.a.s.service.PaymentFeignService : [PaymentFeignService#getPaymentById] transfer-encoding: chunked
2021-05-31 10:12:43.791 DEBUG 548 --- [p-nio-80-exec-1] c.a.s.service.PaymentFeignService : [PaymentFeignService#getPaymentById]
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"}}
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)
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