当前位置: 首页 > news >正文

[000-01-008].第05节:OpenFeign高级特性-日志打印功能

我的后端学习大纲

SpringCloud学习大纲


1、日志打印功能:

  • 1.Feign 提供了日志打印功能,我们可以通过配置来调整日志级别,从而了解 Feign 中 Http 请求的细节,说白了就是对Feign接口的调用情况进行监控和输出

2、日志级别:

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

3、配置开启日志功能:

3.1.配置日志bean

package com.atguigu.cloud.config;
import feign.Logger;
import feign.Retryer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class FeignConfig{@Beanpublic Retryer myRetryer(){return Retryer.NEVER_RETRY; //默认}@BeanLogger.Level feignLoggerLevel() {return Logger.Level.FULL;}
}

3.2.YML文件里需要开启日志的Feign客户端:

  • 1.公式(三段):logging.level + 含有@FeignClient注解的完整带包名及接口名+debug

在这里插入图片描述

  • 2.YML配置:
	# feign日志以什么级别监控哪个接口logging:level:com:atguigu:cloud:apis:PayFeignApi: debug 

3.3.测试查看后台日志:

a.带着压缩调用:

在这里插入图片描述

b.去掉压缩调用:

在这里插入图片描述

3.4测试重试机制的日志:

a.更改类FeignConfig.java,配置重试策略

package com.atguigu.cloud.config;import feign.Logger;
import feign.Retryer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;@Configuration
public class FeignConfig{@Beanpublic Retryer myRetryer(){//最大请求次数为3(1+2),初始间隔时间为100ms,重试间最大间隔时间为1sreturn new Retryer.Default(100,1,3);}@BeanLogger.Level feignLoggerLevel() {return Logger.Level.FULL;}
}

b.配置YML:

server:port: 80spring:application:name: cloud-consumer-openfeign-order####Spring Cloud Consul for Service Discoverycloud:consul:host: localhostport: 8500discovery:prefer-ip-address: true #优先使用服务ip进行注册service-name: ${spring.application.name}openfeign:client:config:default:#cloud-payment-service:#连接超时时间connectTimeout: 2000#读取超时时间readTimeout: 2000httpclient:hc5:enabled: truecompression:request:enabled: truemin-request-size: 2048mime-types: text/xml,application/xml,application/jsonresponse:enabled: true# feign日志以什么级别监控哪个接口
logging:level:com:atguigu:cloud:apis:PayFeignApi: debug

c.测试:

  • 发送请求:http://localhost/feign/pay/get/1

d.控制台打印:

在这里插入图片描述

e.完整的YML:

server:port: 80spring:application:name: cloud-consumer-openfeign-order####Spring Cloud Consul for Service Discoverycloud:consul:host: localhostport: 8500discovery:prefer-ip-address: true #优先使用服务ip进行注册service-name: ${spring.application.name}openfeign:client:config:default:connectTimeout: 2000 #连接超时时间readTimeout: 2000 #读取超时时间httpclient:hc5:enabled: truecompression:request:enabled: truemin-request-size: 2048mime-types: text/xml,application/xml,application/jsonresponse:enabled: true#cloud-payment-service:#connectTimeout: 4000 #连接超时时间#readTimeout: 4000 #读取超时时间# feign日志以什么级别监控哪个接口
logging:level:com:atguigu:cloud:apis:PayFeignApi: debug

http://www.mrgr.cn/news/26161.html

相关文章:

  • 树形结构构建的两种方式
  • 并发编程(九)
  • 免费的成绩查询微信小程序,让家长轻松掌握学生表现
  • 基于人工智能的自动驾驶系统项目教学指南
  • 机器学习文献|基于循环细胞因子特征,通过机器学习算法预测NSCLC免疫治疗结局
  • ESP8266+eclipse+AP+最简单webserver
  • 墨西哥海外仓市场如何?如何选择墨西哥海外仓系统?
  • vue权限菜单的详细开发步骤流程。
  • 《C++中动态数组的实现与探索》
  • SPDK 部署NVMe over TCP
  • 香港打工人√三天通过微软mos认证
  • el-cascader异步级联选择器选择省市区,在百度地图上显示坐标
  • 【软件使用-MEGA】构建进化树报错
  • oracle select字段有子查询会每次执行子查询吗
  • 中国水土保持能力防治数据集(1992-2019)
  • 高校课堂教学管理系统小程序的设计
  • 如何看待 IBM 中国研发部裁员
  • 命令行创建openstack云主机
  • Visual Studio Installer 2022 安装提示正在提取文件 进度条不动 0B每秒
  • OpenAI o1 Review 大模型PHD水平数理推理能力 OpenAI o1 vs GPT4o vs Gemini vs Claude