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文件,但是在微服务架构中全部手动修改的话很麻烦而且不易维护 ...
随机推荐
- yum install mariadb安装数据库开启不了
centos7内置的MySQL镜像已经放弃Oracle公司的MySQL,改用MySQL的分支数据库mariaDB,使用以下安装mariadb: yum install mariadb 然后使用命令sy ...
- V4L2开发要点【转】
转自:https://blog.csdn.net/mr_raptor/article/details/7441141 首先来看 Read/Write ,如果 VIDIOC_QUERYCAP 调用返回的 ...
- 前端清除缓存方法(微信缓存引起的bug)
bug1:在新版微信中,部门安卓机子(华为)出现window.location.href/window.location.reload....等方法来刷新本页面链接,发现页面没有被刷新,经过排查,发现 ...
- python3+selenium框架设计05-配置文件和浏览器引擎类
python3配置文件的增删改查等操作可以使用内置的ConfigParser模块,可以自行百度学习,也可以看Python3学习笔记27-ConfigParser模块 配置文件一般存放着环境信息,比如u ...
- WARN: Establishing SSL connection
在我们使用连接MySQL数据库时会出现这样的提示: Tue Aug 29 13:24:29 CST 2017 WARN: Establishing SSL connection without ser ...
- linux系统快捷键
tab 补全命令 两次tab 列出所有以字符前缀开头的命令 ctrl A 把光标移到命令行开头 ctrl E 把光标移到命令行结尾 ctrl C 强制终止当前的命令 ct ...
- 5分钟搞定Nginx安装
1. 安装gcc(centos 7之后一般已自带,可以在第6步失败后再安装) yum install gcc gcc-c++ 2. 安装pcre yum install -y pcre pcr ...
- linux流量异常查看哪些程序占用的
Linux下进程/程序网络带宽占用情况查看工具 -- NetHogs http://www.vpser.net/manage/nethogs.html 来自. 最后略有修改 之前VPS侦探曾 ...
- Python-WEB -VUE初识
走进Vue_渐进式 JavaScript 框架 通过对框架的了解与运用程度,来决定其在整个项目中的应用范围,最终可以独立以框架方式完成整个web前端项目 what -- 什么是Vue 可以独立完成前后 ...
- Unix的哲学
先讲两个很老的小故事. 第一个故事. 有一家日本最大的化妆品公司,收到了用户的投诉.用户抱怨买来的肥皂盒是空的.这家公司为了防止再发生这样的事故,很辛苦地发明了一台X光检查器,能够透视每一个出货的肥皂 ...