美文网首页Spring Cloud
Fegin 请求日志查看配置

Fegin 请求日志查看配置

作者: 不想当码农的程序员 | 来源:发表于2017-10-09 19:53 被阅读157次

在spring cloud的项目中,使用Fegin做多个服务之间的调用,是很常见的事情,但是调用失败后虽然能进入熔断器中,但是具体的失败原因,或者日志,如果能看到,那么对开发调试,将会有很大的帮助。

步骤

1、配置FeignConfig

@Configuration
public class FeignConfig {


    /**
     * 配置请求重试
     * 
     */
    @Bean
    public Retryer feignRetryer() {
        return new Retryer.Default(200, SECONDS.toMillis(2), 10);
    }


    /**
     * 设置请求超时时间
     *默认
         * public Options() {
         * this(10 * 1000, 60 * 1000);
         * }
     *
     */
    @Bean
    Request.Options feignOptions() {
        return new Request.Options(60 * 1000, 60 * 1000);
    }



    /**
     * 打印请求日志
     * @return
     */
    @Bean
    public feign.Logger.Level multipartLoggerLevel() {
        return feign.Logger.Level.FULL;
    }

}

2、配置 FeignClient

@FeignClient(value = "test-service", fallback = TestServiceHystrix.class, configuration = FeignConfig.class)
public interface TestServiceClient {

    @PostMapping( value = "/upload",produces = {MediaType.APPLICATION_JSON_UTF8_VALUE},consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
     UpLoadResult upload(@RequestParam("upload") MultipartFile file);
}

3、请求接口,查看控制台日志

2017-10-09 19:31:01.438 DEBUG [test-sys-test-service,e2818797113202e3,e2818797113202e3,true] 12972 --- [nio-8773-exec-2] 

c.x.test.client.testServiceClient       :

 [testServiceClient#upload] ---> POST http://test-service/upload?


upload=org.springframework.mock.web.MockMultipartFile%4021d2b412 HTTP/1.1
2017-10-09 19:31:01.438 DEBUG [test-sys-test-service,e2818797113202e3,e2818797113202e3,true] 12972 --- [nio-8773-exec-2] c.x.test.client.testServiceClient       : 


[testServiceClient#upload] Accept: application/json;charset=UTF-8


2017-10-09 19:31:01.439 DEBUG [test-sys-test-service,e2818797113202e3,e2818797113202e3,true] 12972 --- [nio-8773-exec-2] c.x.test.client.testServiceClient       : 

[testServiceClient#upload] Content-Type: multipart/form-data


2017-10-09 19:31:01.439 DEBUG [test-sys-test-service,e2818797113202e3,e2818797113202e3,true] 12972 --- [nio-8773-exec-2] c.x.test.client.testServiceClient       :

 [testServiceClient#upload] ---> END HTTP (0-byte body)
 

[test-sys-test-service,e2818797113202e3,e2818797113202e3,true] 12972 --- [nio-8773-exec-2] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@45a92394: startup date [Mon Oct 09 19:31:01 CST 2017]; parent: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@64b3b1ce
2017-10-09 19:31:01.533  INFO 

[test-sys-test-service,e2818797113202e3,e2818797113202e3,true] 12972 --- [nio-8773-exec-2] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2017-10-09 19:31:01.776  INFO

 [test-sys-test-service,e2818797113202e3,e2818797113202e3,true] 12972 --- [nio-8773-exec-2] c.netflix.config.ChainedDynamicProperty  : Flipping property: test-test-service.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647
2017-10-09 19:31:01.819  INFO [test-sys-test-service,e2818797113202e3,e2818797113202e3,true] 12972 --- [nio-8773-exec-2] c.n.u.concurrent.ShutdownEnabledTimer    : Shutdown hook installed for: NFLoadBalancer-PingTimer-test-test-service
2017-10-09 19:31:01.824  INFO

 [test-sys-test-service,e2818797113202e3,e2818797113202e3,true] 12972 --- [nio-8773-exec-2] c.netflix.loadbalancer.BaseLoadBalancer  : Client: test-test-service instantiated a LoadBalancer: DynamicServerListLoadBalancer:{NFLoadBalancer:name=test-test-service,current list of Servers=[],Load balancer stats=Zone stats: {},Server stats: []}ServerList:null
2017-10-09 19:31:01.830  INFO [test-sys-test-service,e2818797113202e3,e2818797113202e3,true] 12972 --- [nio-8773-exec-2] c.n.l.DynamicServerListLoadBalancer      : Using serverListUpdater PollingServerListUpdater
2017-10-09 19:31:01.851  INFO [test-sys-test-service,e2818797113202e3,e2818797113202e3,true] 12972 --- [nio-8773-exec-2] c.netflix.config.ChainedDynamicProperty  : Flipping property: test-test-service.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647
2017-10-09 19:31:01.852  INFO [test-sys-test-service,e2818797113202e3,e2818797113202e3,true] 12972 --- [nio-8773-exec-2] c.n.l.DynamicServerListLoadBalancer      : 

DynamicServerListLoadBalancer for client test-test-service initialized: DynamicServerListLoadBalancer:{NFLoadBalancer:name=test-test-service,current list of Servers=[10.10.0.176:8771],Load balancer stats=Zone stats: {defaultzone=[Zone:defaultzone; Instance count:1;   Active connections count: 0;    Circuit breaker tripped count: 0;   Active connections per server: 0.0;]


},Server stats: [[Server:10.20.0.176:8700;  Zone:defaultZone;


    Total Requests:0;   Successive connection failure:0;    Total blackout seconds:0;   Last connection made:Thu Jan 01 08:00:00 CST 1970;  First connection made: Thu Jan 01 08:00:00 CST 1970;    Active Connections:0;   total failure count in last (1000) msecs:0; average resp time:0.0;  90 percentile resp time:0.0;    95 percentile resp time:0.0;    min resp time:0.0;  max resp time:0.0;  stddev resp time:0.0]
]}ServerList:org.springframework.cloud.netflix.ribbon.eureka.DomainExtractingServerList@15044fde
2017-10-09 19:31:02.047 DEBUG [test-sys-test-service,e2818797113202e3,e2818797113202e3,true] 12972 --- [nio-8773-exec-2] c.x.test.client.testServiceClient       : [testServiceClient#upload] <--- HTTP/1.1 500  (607ms)
2017-10-09 19:31:02.047 DEBUG [test-sys-test-service,e2818797113202e3,e2818797113202e3,true] 12972 --- [nio-8773-exec-2] c.x.test.client.testServiceClient       : [testServiceClient#upload] cache-control: no-cache, no-store, max-age=0, must-revalidate
2017-10-09 19:31:02.047 DEBUG [test-sys-test-service,e2818797113202e3,e2818797113202e3,true] 12972 --- [nio-8773-exec-2] c.x.test.client.testServiceClient       : [testServiceClient#upload] connection: close
2017-10-09 19:31:02.047 DEBUG [test-sys-test-service,e2818797113202e3,e2818797113202e3,true] 12972 --- [nio-8773-exec-2] c.x.test.client.testServiceClient       : [testServiceClient#upload] content-type: application/json;charset=UTF-8
2017-10-09 19:31:02.047 DEBUG [test-sys-test-service,e2818797113202e3,e2818797113202e3,true] 12972 --- [nio-8773-exec-2] c.x.test.client.testServiceClient       : [testServiceClient#upload] date: Mon, 09 Oct 2017 11:31:07 GMT
2017-10-09 19:31:02.047 DEBUG [test-sys-test-service,e2818797113202e3,e2818797113202e3,true] 12972 --- [nio-8773-exec-2] c.x.test.client.testServiceClient       : [testServiceClient#upload] expires: 0
2017-10-09 19:31:02.048 DEBUG [test-sys-test-service,e2818797113202e3,e2818797113202e3,true] 12972 --- [nio-8773-exec-2] c.x.test.client.testServiceClient       : [testServiceClient#upload] pragma: no-cache
2017-10-09 19:31:02.048 DEBUG [test-sys-test-service,e2818797113202e3,e2818797113202e3,true] 12972 --- [nio-8773-exec-2] c.x.test.client.testServiceClient       : [testServiceClient#upload] transfer-encoding: chunked
2017-10-09 19:31:02.048 DEBUG [test-sys-test-service,e2818797113202e3,e2818797113202e3,true] 12972 --- [nio-8773-exec-2] c.x.test.client.testServiceClient       : [testServiceClient#upload] x-application-context: test-test-service:dev:8771
2017-10-09 19:31:02.048 DEBUG [test-sys-test-service,e2818797113202e3,e2818797113202e3,true] 12972 --- [nio-8773-exec-2] c.x.test.client.testServiceClient       : [testServiceClient#upload] x-content-type-options: nosniff
2017-10-09 19:31:02.048 DEBUG [test-sys-test-service,e2818797113202e3,e2818797113202e3,true] 12972 --- [nio-8773-exec-2] c.x.test.client.testServiceClient       : [testServiceClient#upload] x-frame-options: DENY
2017-10-09 19:31:02.048 DEBUG [test-sys-test-service,e2818797113202e3,e2818797113202e3,true] 12972 --- [nio-8773-exec-2] c.x.test.client.testServiceClient       : [testServiceClient#upload] x-xss-protection: 1; mode=block
2017-10-09 19:31:02.048 DEBUG [test-sys-test-service,e2818797113202e3,e2818797113202e3,true] 12972 --- [nio-8773-exec-2] c.x.test.client.testServiceClient       : [testServiceClient#upload] 
2017-10-09 19:31:02.049 DEBUG [test-sys-test-service,e2818797113202e3,e2818797113202e3,true] 12972 --- [nio-8773-exec-2] c.x.test.client.testServiceClient       : [testServiceClient#upload]


 {
  "code" : 500,
  "error" : "Internal Server Error",
  "data" : null
}



2017-10-09 19:31:02.049 DEBUG [test-sys-test-service,e2818797113202e3,e2818797113202e3,true] 12972 --- [nio-8773-exec-2] c.x.test.client.testServiceClient       : [testServiceClient#upload] <--- END HTTP (72-byte body)
2017-10-09 19:31:02.061  INFO [test-sys-test-service,e2818797113202e3,e2818797113202e3,true] 12972 --- [nio-8773-exec-2] c.x.t.c.hystrix.PlUserServiceHystrix     : ---upload hystrix---

从我的日志中可以看到,这次请求失败了,并且能看到发出的请求url,方法类型,返回数据,负载均衡信息,请求的具体的集群ip等,这对我们调试有很大的帮助

关键设置

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

//-----------------------------------
configuration = FeignConfig.class

点击获取优惠券

点我获取阿里云优惠券

我的官网


我的博客

我的官网http://guan2ye.com
我的CSDN地址http://blog.csdn.net/chenjianandiyi
我的简书地址http://www.jianshu.com/u/9b5d1921ce34
我的githubhttps://github.com/javanan
我的码云地址https://gitee.com/jamen/
阿里云优惠券https://promotion.aliyun.com/ntms/act/ambassador/sharetouser.html?userCode=vf2b5zld&utm_source=vf2b5zld

阿里云教程系列网站http://aliyun.guan2ye.com

1.png

我的开源项目spring boot 搭建的一个企业级快速开发脚手架

1.jpg

相关文章

  • Fegin 请求日志查看配置

    在spring cloud的项目中,使用Fegin做多个服务之间的调用,是很常见的事情,但是调用失败后虽然能进入熔...

  • OpenFegin日志打印功能

    OpenFegin日志打印功能 Fegin 提供了日志打印功能,我们可以通过配置来调整日志级别,从而了解 Fegi...

  • 91104-nginx failed(13:Permission

    问题背景 nginx 配置好以后 发现请求不能转发 问题分析 查看Nginx 日志,Linux 日志默认路径 ht...

  • 线上环境如何查看实时,历史QPS。

    引用于:如何查看线上机器的QPStomcat访问(access)日志配置、记录Post请求参数 1. 需求: 服务...

  • 通过 gc.log 调优 JVM

    一、GC 日志查看 GC 日志默认是关闭的,需要查看 GC 日志首先需要开启 GC 日志。 常用 GC 日志的配置...

  • logback 配置

    代码高亮配置: 用来过滤日志 经过配置,可以将各个日志分开,方便查看.

  • 我的开发笔记

    Linux命令查看日志 查看日文件关键字附近前后50条日志 查看指定时间范围内的日志 HTTP Get 请求curl

  • SpringCloud灰度发布

    一: 调用链分析 请求==>网关==>服务Resttemplate调用==>服务请求==>网关==>服务Fegin...

  • 【SpringCloud-Alibaba系列教程】9.Fegin

    我们开始吧 首先我们需要在配置文件中配置Fegin的相关规则 然后我们创建容错实现类 其次就是在Fegin调用接口...

  • 日志管理

    错误日志 作用 MySQL启动及工作过程中,查询状态、报错及告警。 如何配置 如何查看错误日志 查看日志时专注查看...

网友评论

    本文标题:Fegin 请求日志查看配置

    本文链接:https://www.haomeiwen.com/subject/lonpyxtx.html