spring cloud feign覆写默认配置级feign client的日志打印
一、覆写fegin的默认配置
1、新增配置类FeignConfiguration.java
package com.config; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import feign.Contract;
import feign.Logger;
@Configuration
public class FeignConfiguration { @Bean
public Contract feignContract() {
//这里可以配置默认配置
return new feign.Contract.Default();
} @Bean
Logger.Level feignLoggerLevel() {
return Logger.Level.FULL;
}
}
需要之一的是此配置文件不能再spring cloud扫描包的路径下,否则会有问题出现
2、定义一个FeignClient2.java
package com.pupeiyuan.feignClient; import java.util.List; import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import com.config.FeignConfiguration;
import com.pupeiyuan.bean.NhReportStatusHistory; import feign.Param;
import feign.RequestLine; @FeignClient(name = "MULTIPLE",configuration = FeignConfiguration.class)
public interface FeignClient2 {
@RequestLine("GET /getDate/{id}")
public List<NhReportStatusHistory> dataList(@Param("id") Long id);
}
3、controller中调用
FeignClientController.java
package com.pupeiyuan.controller; import java.util.List; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import com.pupeiyuan.bean.NhReportStatusHistory;
import com.pupeiyuan.feignClient.FeignClient2;
import com.pupeiyuan.feignClient.UserFeignClient; @RestController
public class FeignClientController { @Autowired
private FeignClient2 feignClient2; @GetMapping("/movie2/{id}")
public List<NhReportStatusHistory> list2(@PathVariable Long id) {
return this.feignClient2.dataList(id);
}
}
实现的效果和上一篇文章是一样的

二、feign client的日志打印
默认情况下feign是没有日志打印出来的,需要增加相关配置:
1、创建Feign的配置文件,并在其中设置日志等级
/**
* Feign 客户端配置
*
* @author xushiling
* @date 2018/8/13
*/
@Configuration
public class FeignConfiguration {
@Bean
Logger.Level feignLoggerLevel() {
//这里记录所有,根据实际情况选择合适的日志level
return Logger.Level.FULL;
}
}
这里的level级别控制如下
NONE, No logging (DEFAULT).
BASIC, Log only the request method and URL and the response status code and execution time.
HEADERS, Log the basic information along with request and response headers.
FULL, Log the headers, body, and metadata for both requests and responses.
NONE, 不记录 (DEFAULT).
BASIC, 仅记录请求方式和URL及响应的状态代码与执行时间.
HEADERS, 日志的基本信息与请求及响应的头.
FULL, 记录请求与响应的头和正文及元数据.
2、在客户端接口指定此配置
package com.pupeiyuan.feignClient; import java.util.List; import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import com.config.FeignConfiguration;
import com.pupeiyuan.bean.NhReportStatusHistory; import feign.Param;
import feign.RequestLine; @FeignClient(name = "MULTIPLE",configuration = FeignConfiguration.class)
public interface FeignClient2 {
@RequestLine("GET /getDate/{id}")
public List<NhReportStatusHistory> dataList(@Param("id") Long id);
}
3、配置文件开启日志记录
application.properties设置:
logging.level.com.haoait.client.UserServiceClient:debug
如果是yml配置文件则做如下配置:
logging:
level:
com.haoait.client.UserServiceClient:debug
日志输出如下:

spring cloud feign覆写默认配置级feign client的日志打印的更多相关文章
- feign三:覆写feign的默认配置及feign的日志
feign三:覆写feign的默认配置及feign的日志 默认配置复写 本项目地址:http://192.168.1.103:7601 本例是通过feign调用 eureka项目中的/eureka/a ...
- Spring Cloud第十一篇 | 分布式配置中心高可用
本文是Spring Cloud专栏的第十一篇文章,了解前十篇文章内容有助于更好的理解本文: Spring Cloud第一篇 | Spring Cloud前言及其常用组件介绍概览 Spring Cl ...
- Spring Cloud(七):配置中心(Git 版与动态刷新)【Finchley 版】
Spring Cloud(七):配置中心(Git 版与动态刷新)[Finchley 版] 发表于 2018-04-19 | 更新于 2018-04-24 | Spring Cloud Confi ...
- SpringCloud学习笔记(10)----Spring Cloud Netflix之声明式 REST客户端 -Feign的高级特性
1. Feign的默认配置 Feign 的默认配置 Spring Cloud Netflix 提供的默认实现类:FeignClientsConfiguration 解码器:Decoder feignD ...
- Spring Cloud Alibaba(二) 配置中心多项目、多配置文件、分目录实现
介绍 之前Spring Cloud Config基础篇这篇文章介绍了Spring Cloud Config 配置中心基础的实现,今天继续聊下Spring Cloud Config 并结合nacos做服 ...
- Spring Cloud中五大神兽总结(Eureka/Ribbon/Feign/Hystrix/zuul)
Spring Cloud中五大神兽总结(Eureka/Ribbon/Feign/Hystrix/zuul) 1.Eureka Eureka是Netflix的一个子模块,也是核心模块之一.Eureka是 ...
- Spring Cloud config之一:分布式配置中心入门介绍
Spring Cloud Config为服务端和客户端提供了分布式系统的外部化配置支持.配置服务器为各应用的所有环境提供了一个中心化的外部配置.它实现了对服务端和客户端对Spring Environm ...
- Spring Cloud(九):配置中心(消息总线)【Finchley 版】
Spring Cloud(九):配置中心(消息总线)[Finchley 版] 发表于 2018-04-19 | 更新于 2018-05-07 | 我们在 Spring Cloud(七):配置中心 ...
- 【SpringCloud构建微服务系列】使用Spring Cloud Config统一管理服务配置
一.为什么要统一管理微服务配置 对于传统的单体应用而言,常使用配置文件来管理所有配置,比如SpringBoot的application.yml文件,但是在微服务架构中全部手动修改的话很麻烦而且不易维护 ...
随机推荐
- python - 中文编码/ASCII
Python 中文编码 为了处理汉字,程序员设计了用于简体中文的GB2312和用于繁体中文的big5. GB2312(1980年)一共收录了7445个字符,包括6763个汉子和682个其他符号. ...
- MySql cmd下的学习笔记 —— 有关子查询的操作(where型,from型,exists型子查询)
先找到goods表 查询goods_id最大的商品 where型的子查询 查询goods_id最大的商品(不能用排序) 把两步写成一步,就是子查询 from型子查询 查找出每种cat_id下goods ...
- 第一节,tensorflow基础构架
1.tensorflow结构 import tensorflow as tfimport numpy as np #create datax_data=np.random.rand(100).asty ...
- 【运维】Dell R710如何开启VT服务
[前言]: 英特尔的硬件辅助虚拟化技术(Virtualization Technology,简称VT技术)是一种设计更简单.实施更高效和可靠的方法. 如果想要在 ...
- k64 datasheet学习笔记35---Analog-to-Digital Converter (ADC)
0.前言 本文主要介绍K64的ADC部分的特性,内部架构,信号描述及操作接口等 1.简介 1.1.ADC模块特性 线性逐次逼近算法,达16bit分辨率 达到4对差分和24个单端模拟量输入 输出模式 差 ...
- 基于tiny4412的Linux内核移植 -- 设备树的展开【转】
转自:https://www.cnblogs.com/pengdonglin137/p/5248114.html#_lab2_3_1 阅读目录(Content) 作者信息 平台简介 摘要 正文 一.根 ...
- POJ3580 SuperMemo splay伸展树,区间操作
题意:实现一种数据结构,支持对一个数列的 6 种操作:第 x 个数到第 y 个数之间的数每个加 D:第 x 个数到第 y 个数之间全部数翻转:第 x 个数到第 y 个数之间的数,向后循环流动 c 次, ...
- sqlserver 导出数据
背景 一看到这个标题,还有这个内容,感觉当初记录这个知识点真是记录的太简单了.不过通过这个知识点我还真想起了当初的一些事情.写的题外话可能更有意思,希望每篇文章我都能加个当时的题外记录.当时一直搞or ...
- Centos 7 安装Docker-ce记录
以前尝试过在centos 6上安装Docker , 需要升级内核,支持aufs,比较麻烦:在使用过程中出现过Docker挂掉的情况,官方建议在64 位 centos 7 上运行,本文将安装步骤记录下来 ...
- 嵌入式程序设计中C/C++代码的优化
虽然使软件正确是一个工程合乎逻辑的最后一个步骤,但是在嵌入式的系统开发中,情况并不总是这样的.出于对低价产品的需求,硬件的设计者需要提供刚好足够的存储器和完成工作的处理能力.所以在嵌入式软件设计的最后 ...