栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Feign 的细粒度与全局 日志打印

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Feign 的细粒度与全局 日志打印

文章目录
  • 一、细粒度 基于JAVA代码的方式配置
  • 二、细粒度 基于配置的方式
    • 三. 全局 ,基于JAVA代码的方式配置
  • 四、全局 , 基于配置的方式


一、细粒度 基于JAVA代码的方式配置
  1. 在Feign接口注解里加configuration 指向一个Logger的配置类
import com.itmuch.contentcenter.domain.dto.user.UserDTO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import ribbonconfiguration.UserCenterFeignConfiguration;

//name:要请求的微服务的名称
@FeignClient(name = "user-center" ,configuration = UserCenterFeignConfiguration.class)
public interface UserCenterFeignClient {

    
    @GetMapping("/users/{id}")
    UserDTO findById(@PathVariable Integer id);
}
  1. 创建Logger的配置类 UserCenterFeignConfiguration
    注意:如果这个类加了@Configuration,那么这个的位置要与启动类是同一级目录,不能让@ComponentScan扫描到
import feign.Logger;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class UserCenterFeignConfiguration {

    @Bean
    public Logger.Level level(){
        return Logger.Level.FULL;
    }
}
  1. 配置yml
    能保证 UserCenterFeignClient 接口所在目录是debug即可
logging:
  level:
    com.itmuch.contentcenter.feignclient.UserCenterFeignClient: DEBUG
二、细粒度 基于配置的方式
  1. 修改yml
logging:
  level:
    com.itmuch.contentcenter.feignclient.UserCenterFeignClient: DEBUG
feign:
  client:
    config:
      user-center: #请求的微服务的名字
        loggerLevel: full

  1. Feign接口
import com.itmuch.contentcenter.domain.dto.user.UserDTO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

//name:要请求的微服务的名称
@FeignClient(name = "user-center")
public interface UserCenterFeignClient {

    
    @GetMapping("/users/{id}")
    UserDTO findById(@PathVariable Integer id);
}
三. 全局 ,基于JAVA代码的方式配置
  1. 修改启动类Feign注解
@EnableFeignClients(defaultConfiguration = GlobalFeignConfiguration.class)

  1. 创建 GlobalFeignConfiguration
import feign.Logger;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class GlobalFeignConfiguration {

    @Bean
    public Logger.Level level(){
        return Logger.Level.FULL;
    }
}
四、全局 , 基于配置的方式
  1. 修改yml
feign:
  client:
    config:
      default: #全局
        loggerLevel: full
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/877462.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号