Springcloud之Feign启用日志

如果我们想追踪Feign客户端发送的数据,就要启用Feign的日志。

Feign在构建被@FeignClient注解修饰的服务客户端时,会为每一个客户端都创建一个feign.Logger实例,这样就可以利用该日志对象的DEBUG模式来帮助分析Feign的请求细节。

实现步骤:
1. 在application.yml中使用 logging.level.<Feign客户端对应的接口的全限定名> 的参数配置格式来开启指定客户端日志.

在这里插入图片描述
注意这里是Feign客户端接口的完整路径,这是我们要监控日志的接口

  1. 但由于Feign客户端默认的Logger.Level对象定义为NONE级别,因此需要对它进行调整. Logger.Level的源码中规定了以下几个级别:
@SpringBootConfiguration
public class FeignLogConfig {
    @Bean
    Logger.Level feignLoggerLevel(){
        return Logger.Level.FULL;
    }
}

运行 程序 [microservice-consumer-feign],查看输出结果。

2020-10-16 15:14:45.634 DEBUG 15604 --- [nio-9999-exec-1] c.y.s.service.IProductClientService      : [IProductClientService#listProduct] <--- HTTP/1.1 200 (799ms)
2020-10-16 15:14:45.634 DEBUG 15604 --- [nio-9999-exec-1] c.y.s.service.IProductClientService      : [IProductClientService#listProduct] cache-control: no-cache, no-store, max-age=0, must-revalidate
2020-10-16 15:14:45.634 DEBUG 15604 --- [nio-9999-exec-1] c.y.s.service.IProductClientService      : [IProductClientService#listProduct] connection: keep-alive
2020-10-16 15:14:45.634 DEBUG 15604 --- [nio-9999-exec-1] c.y.s.service.IProductClientService      : [IProductClientService#listProduct] content-type: application/json;charset=UTF-8
2020-10-16 15:14:45.634 DEBUG 15604 --- [nio-9999-exec-1] c.y.s.service.IProductClientService      : [IProductClientService#listProduct] date: Fri, 16 Oct 2020 07:14:45 GMT
2020-10-16 15:14:45.634 DEBUG 15604 --- [nio-9999-exec-1] c.y.s.service.IProductClientService      : [IProductClientService#listProduct] expires: 0
2020-10-16 15:14:45.634 DEBUG 15604 --- [nio-9999-exec-1] c.y.s.service.IProductClientService      : [IProductClientService#listProduct] keep-alive: timeout=60
2020-10-16 15:14:45.634 DEBUG 15604 --- [nio-9999-exec-1] c.y.s.service.IProductClientService      : [IProductClientService#listProduct] pragma: no-cache
2020-10-16 15:14:45.634 DEBUG 15604 --- [nio-9999-exec-1] c.y.s.service.IProductClientService      : [IProductClientService#listProduct] transfer-encoding: chunked
2020-10-16 15:14:45.634 DEBUG 15604 --- [nio-9999-exec-1] c.y.s.service.IProductClientService      : [IProductClientService#listProduct] x-content-type-options: nosniff
2020-10-16 15:14:45.634 DEBUG 15604 --- [nio-9999-exec-1] c.y.s.service.IProductClientService      : [IProductClientService#listProduct] x-frame-options: DENY
2020-10-16 15:14:45.634 DEBUG 15604 --- [nio-9999-exec-1] c.y.s.service.IProductClientService      : [IProductClientService#listProduct] x-xss-protection: 1; mode=block
2020-10-16 15:14:45.635 DEBUG 15604 --- [nio-9999-exec-1] c.y.s.service.IProductClientService      : [IProductClientService#listProduct] 
2020-10-16 15:14:45.636 DEBUG 15604 --- [nio-9999-exec-1] c.y.s.service.IProductClientService      : [IProductClientService#listProduct] [{"productId":1,"productName":"a","productDesc":"good"}]
2020-10-16 15:14:45.637 DEBUG 15604 --- [nio-9999-exec-1] c.y.s.service.IProductClientService      : [IProductClientService#listProduct] <--- END HTTP (56-byte body)

如果想只对一个Feign客户端启动日志,就把配置写入单独Feign的application下。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值