首页 > 其他分享 >openfeign开启日志

openfeign开启日志

时间:2023-04-01 16:36:21浏览次数:37  
标签:feign http openfeign 开启 getUser 日志 public localhost

openfeign的日志级别有:

  1. NONE:默认,不开启日志
  2. BASIC:只记录请求方法和URL以及响应状态代码和执行时间
  3. HEADERS:记录基本信息以及请求和响应标头。
  4. FULL:记录请求和响应的标题、正文和元数据。

 
 

全局日志

加入Logger.Level Bean:

@Configuration
public class MyConfigration {

    @Bean
    public Logger.Level level() {
        return Logger.Level.FULL;
    }
}

访问http://localhost:8003/helloByFeign,还是没看到日志,还需要改变SpringBoot的日志级别,在application.properties加入:

logging.level.com.example.feign=debug

com.example.feign是feign所在的包。

重新访问http://localhost:8003/helloByFeign:

 
 

还可以在application.properties加入

feign.client.config.default.loggerLevel=FULL

开启openfeign的全局日志级别。

 

单个feign的日志级别

新建UserProvider模块,引入

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
    </dependency>

并设置parent为:

<parent>
    <groupId>com.springCloudDemo</groupId>
    <artifactId>SpringCloudDemo</artifactId>
    <version>1.0.1-SNAPSHOT</version>
</parent>

在application.properties增加配置:

server.port=8004

spring.application.name=userProvider

eureka.client.service-url.defaultZone=http://user:123@localhost:8761/eureka/

并增加controller:

@RestController
public class UserController {

    @RequestMapping("/getUser")
    public Map<String, Object>  getUser() {
        Map<String, Object> map = new HashMap<>();
        map.put("name","李四");
        map.put("age",30);
        return map;
    }
}

在ConsumerByRibbon新建userFeign包,增加feign调用:

@FeignClient(value = "userProvider")
public interface UserFeign {

     @RequestMapping("/getUser")
     Map<String, Object> getUser();
}

在application.properties加入:

logging.level.com.example.userFeign=debug

并在controller增加:

@Autowired
UserFeign userFeign;

@RequestMapping("/getUser")
public Map<String, Object> getUser() {
    return userFeign.getUser();
}

 
 

修改HelloFeign:

@FeignClient(value = "producer",configuration = HelloConfigration.class)
public interface HelloFeign {
    @RequestMapping("/hello")
    public String hello(@RequestParam String name);
}

@Configuration
public class HelloConfigration {

   @Bean
    public Logger.Level level() {
        return Logger.Level.FULL;
    }
}

注意HelloConfigration类不要放在SpringBoot的包扫描路径下。

注释掉全局日志配置,访问http://localhost:8003/helloByFeign,看到:

 
在访问http://localhost:8003/getUser,可以见到没有日志输出。HelloFeign可以打印日志,UserFeign不能打印日志。

 
 

还可以在application.properties加入:

feign.client.config.producer.loggerLevel=FULL

producer是feign要调用的服务名。
 
去除HelloFeign类上的configuration属性,访问http://localhost:8003/helloByFeign和http://localhost:8003/getUser,看到HelloFeign可以打印日志,UserFeign不能打印日志。

标签:feign,http,openfeign,开启,getUser,日志,public,localhost
From: https://www.cnblogs.com/shigongp/p/17278700.html

相关文章

  • SpringCloud之openFeign
    FeignOpenFeign是Netflix开发的声明式、模板化的HTTP请求客户端。可以更加便捷、优雅地调用httpapi。OpenFeign会根据带有注解的函数信息构建出网络请求的模板,在发送网络请求之前,OpenFeign会将函数的参数值设置到这些请求模板中。feign主要是构建微服务消费端。只要使用OpenF......
  • asp.net core 开启gzip压缩
    //第一步:配置gzip与br的压缩等级为最优services.Configure<BrotliCompressionProviderOptions>(options=>{options.Level=CompressionLevel.Optimal;});services.Configure<GzipCompressionProvid......
  • 通过Sysmon+Nxlogs收集Windows Server 2012服务器日志-并以Syslog形式发送Json格式数
    0x01环境介绍WindowsServer2012已经安装部署好了域控,目的除了收集Windows服务器本身的日志外还收集域控环境下的各种日志。0x02Nxlog配置和使用使用社区版本即可,下载地址:https://nxlog.co/downloads/nxlog-ce#nxlog-community-edition使用的版本是当前最新版本安装过程就省略,......
  • linux日志总结
    0x00前言Linux系统拥有非常灵活和强大的日志功能,可以保存几乎所有的操作记录,并可以从中检索出我们需要的信息。本文简介一下Linux系统日志及日志分析技巧。0x01日志简介1.1日志服务syslogd介绍说到Linux的日志,就不得不提到syslogd。它是大部分Linux发行版默认的......
  • 有度即时通统一工作门户助力政企单位开启数字化办公新模式
    为了提高办公效率,许多政企内部都会采用数套以上的办公系统平台,但这些平台相互之间都是独立的,形成了信息孤岛。政企内部人员在使用的时候需要来回切换,很容易出现信息遗漏和处理不及时的情况,阻碍了政企内部办公效率的提升。因此,不少政企迫切需要一款能够整合内部已有系统的的数字化......
  • 面向chatgpt运维:根据自定义的日志统计访问用户数
    Craftedby[Genie](https://marketplace.visualstudio.com/items?itemName=genieai.chatgpt-vscode)You如何使用awk统计访问用户数,我的日志格式如下:{"level":"info","ts":"2023/03/3108:58:03","msg":"/api/v1/goods/project&quo......
  • 一个机器开启多个redis
    一个机器开启多个redis复制redis.conf(可以先查一下redis.conf路径在哪里,find/-nameredis.conf)cpredis.confredis3.conf修改port、pidfile(命令行下用/port可以快速查询,按n查找下一个)port6381​pidfile/var/run/redis_6381.pid注意路径是否写对src/redis-s......
  • 客户端日志和异常处理
    目录一.使用Serilog结构化日志记录日志信息二.捕获全局异常三.使用AOP统一处理异常一.使用Serilog结构化日志记录日志信息Serilog包的引用和使用语法都可以在网上找到(https://github.com/serilog/serilog/wiki/),不再赘述,这里仅分享一下自己在项目中的简单使用。FileLogHelpe......
  • jenkins 彩色日志显示
    目录jenkins彩色日志显示转自jenkins彩色日志显示示例:这里用到ansiColor插件,在Jenkins输出有颜色的日志信息流水线语法的生成ansiColor('xterm'){//someblock}tools.groovypackageorg.devops//格式化输出defPrintMes(value,color){colors=['red'......
  • 使用 Oracle LogMiner 分析重做日志
    概述我们知道oracle的redo和归档日志,记录了数据库的事务的相关信息。在日常的数据库管理过程中,我们有时需要,查看特定时刻特定用户在数据库上执行的操作。这时我们可以通过用logminer分析日志文件获取相关信息。logminer分析归档日志文件所获得的信息并不是原始的操作信息,而是等......