Version: Next
OpenFeign 日志增强
详细打印 OpenFeign 远程服务调用的各种信息
- OpenFeign 支持的日志级别
级别 含义 NONE
默认:不显示任何日志 BASIC
仅记录请求方法、URL、响应状态码及执行时间 HEADERS
除了 BASIC
中定义的信息之外,还包括请求和响应的头信息FULL
除了 HEADERS
中定义的信息之外,还有请求和响应的正文及元数据
开启日志增强
在
consumer-feign-order80
中
- 定义一个 Spring 配置类,
FeignConfig
- 注意:引入的是
feign.Logger
@Configurationpublic class FeignConfig {@BeanLogger.Level feignLoggerLevel() {return Logger.Level.FULL;}}
application.yaml
添加日志设置:指定以 什么级别 监听 哪个接口server:port: 80#这里只把feign做客户端用,不注册进eurekaeureka:client:#表示是否将自己注册进EurekaServer默认为trueregister-with-eureka: falseservice-url:#defaultZone: http://localhost:7001/eurekadefaultZone: http://eureka7001.com:7001/eureka/,http://eureka7002.com:7002/eureka/#设置feign客户端超时时间(OpenFeign默认支持ribbon)ribbon:#指的是建立连接后从服务器读取到可用资源所用的时间ReadTimeout: 5000#指的是建立连接所用的时间,适用于网络状况正常的情况下,两端连接所用的实际ConnectTimeout: 5000logging:level:#feign日志以什么级别监控那个接口com.bsx.springcloud.service.PaymentFeignService: debug
- 重启,访问
http://127.0.0.1:80/consumer/payment/get/2
Spring Boot 后台日志
2021-01-09 20:23:23.849 DEBUG 49168 --- [p-nio-80-exec-1] c.b.s.service.PaymentFeignService : [PaymentFeignService#getPaymentById] ---> GET http://CLOUD-PAYMENT-SERVICE/payment/get/2 HTTP/1.1
2021-01-09 20:23:23.851 DEBUG 49168 --- [p-nio-80-exec-1] c.b.s.service.PaymentFeignService : [PaymentFeignService#getPaymentById] ---> END HTTP (0-byte body)
2021-01-09 20:23:24.130 INFO 49168 --- [p-nio-80-exec-1] c.netflix.config.ChainedDynamicProperty : Flipping property: CLOUD-PAYMENT-SERVICE.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647
2021-01-09 20:23:24.185 INFO 49168 --- [p-nio-80-exec-1] c.n.u.concurrent.ShutdownEnabledTimer : Shutdown hook installed for: NFLoadBalancer-PingTimer-CLOUD-PAYMENT-SERVICE
2021-01-09 20:23:24.186 INFO 49168 --- [p-nio-80-exec-1] c.netflix.loadbalancer.BaseLoadBalancer : Client: CLOUD-PAYMENT-SERVICE instantiated a LoadBalancer: DynamicServerListLoadBalancer:{NFLoadBalancer:name=CLOUD-PAYMENT-SERVICE,current list of Servers=[],Load balancer stats=Zone stats: {},Server stats: []}ServerList:null
2021-01-09 20:23:24.201 INFO 49168 --- [p-nio-80-exec-1] c.n.l.DynamicServerListLoadBalancer : Using serverListUpdater PollingServerListUpdater
2021-01-09 20:23:24.307 INFO 49168 --- [p-nio-80-exec-1] c.netflix.config.ChainedDynamicProperty : Flipping property: CLOUD-PAYMENT-SERVICE.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647
2021-01-09 20:23:24.310 INFO 49168 --- [p-nio-80-exec-1] c.n.l.DynamicServerListLoadBalancer : DynamicServerListLoadBalancer for client CLOUD-PAYMENT-SERVICE initialized: DynamicServerListLoadBalancer:{NFLoadBalancer:name=CLOUD-PAYMENT-SERVICE,current list of Servers=[192.168.0.101:8081],Load balancer stats=Zone stats: {defaultzone=[Zone:defaultzone; Instance count:1; Active connections count: 0; Circuit breaker tripped count: 0; Active connections per server: 0.0;]
},Server stats: [[Server:192.168.0.101:8081; Zone:defaultZone; Total Requests:0; Successive connection failure:0; Total blackout seconds:0; Last connection made:Thu Jan 01 08:00:00 CST 1970; First connection made: Thu Jan 01 08:00:00 CST 1970; Active Connections:0; total failure count in last (1000) msecs:0; average resp time:0.0; 90 percentile resp time:0.0; 95 percentile resp time:0.0; min resp time:0.0; max resp time:0.0; stddev resp time:0.0]
]}ServerList:org.springframework.cloud.netflix.ribbon.eureka.DomainExtractingServerList@367a83c4
2021-01-09 20:23:24.552 DEBUG 49168 --- [p-nio-80-exec-1] c.b.s.service.PaymentFeignService : [PaymentFeignService#getPaymentById] <--- HTTP/1.1 200 (701ms)
2021-01-09 20:23:24.552 DEBUG 49168 --- [p-nio-80-exec-1] c.b.s.service.PaymentFeignService : [PaymentFeignService#getPaymentById] connection: keep-alive
2021-01-09 20:23:24.553 DEBUG 49168 --- [p-nio-80-exec-1] c.b.s.service.PaymentFeignService : [PaymentFeignService#getPaymentById] content-type: application/json
2021-01-09 20:23:24.553 DEBUG 49168 --- [p-nio-80-exec-1] c.b.s.service.PaymentFeignService : [PaymentFeignService#getPaymentById] date: Sat, 09 Jan 2021 12:23:24 GMT
2021-01-09 20:23:24.553 DEBUG 49168 --- [p-nio-80-exec-1] c.b.s.service.PaymentFeignService : [PaymentFeignService#getPaymentById] keep-alive: timeout=60
2021-01-09 20:23:24.553 DEBUG 49168 --- [p-nio-80-exec-1] c.b.s.service.PaymentFeignService : [PaymentFeignService#getPaymentById] transfer-encoding: chunked
2021-01-09 20:23:24.553 DEBUG 49168 --- [p-nio-80-exec-1] c.b.s.service.PaymentFeignService : [PaymentFeignService#getPaymentById]
2021-01-09 20:23:24.555 DEBUG 49168 --- [p-nio-80-exec-1] c.b.s.service.PaymentFeignService : [PaymentFeignService#getPaymentById] {"code":200,"message":"查询成功,端口号: 8081","data":{"id":2,"serial":"长大002"}}
2021-01-09 20:23:24.555 DEBUG 49168 --- [p-nio-80-exec-1] c.b.s.service.PaymentFeignService : [PaymentFeignService#getPaymentById] <--- END HTTP (92-byte body)
2021-01-09 20:23:25.205 INFO 49168 --- [erListUpdater-0] c.netflix.config.ChainedDynamicProperty : Flipping property: CLOUD-PAYMENT-SERVICE.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647