Fegin 请求日志查看配置

在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/

时间: 2024-10-09 13:58:04

Fegin 请求日志查看配置的相关文章

Apache日志查看与日志格式配置参数详解

一.定义日志格式 很久以前,日志文件只有一种格式,这就是"公共格式",许多人已经习惯于使用这种格式.随后出现了定制日志格式,而且看起来定制日志格式更很受欢迎,即使公共日志格式本身也重新用定制日志格式定义.本文介绍的就是如何随心所欲地定制日志文件的格式.如何让日志文件记录自己想要的信息. 定制日志文件的格式涉及到两个指令,即LogFormat指令和CustomLog指令,默认httpd.conf文件提供了关于这两个指令的几个示例. LogFormat指令定义格式并为格式指定一个名字,以后

查看LoadRunner脚本请求日志和服务器返回值方法

1.  查看所有请求日志和请求响应信息: 采用LoadRunner工具Run-time settings或按键盘F4,选择LOG设置,选择Extended log->Data returned by server和Parameter substitution,就可以搞定,但是这里设置是记录所有请求的日志. 详细介绍Extended log中Data returned by server.Parameter substitution.Advanced trace的作用: (1).选择Data re

cxf 3.1.5 spring 发布webservice ,不打印客户端的请求日志

问题描述 cxf 3.1.5 spring 发布webservice ,不打印客户端的请求日志 cxf 3.1.5 spring 发布webservice ,不打印客户端的请求日志, jaxws:endpoint 发布方式,怎么配置?非常感谢

Laravel 集成的 Monolog 库对日志进行配置和记录实例

对于大型系统而言,日志是不可或缺的模块,Laravel自然也对日志提供了完善的支持.目前Laravel集成了强大的Monolog库进行日志记录.下面我们就来大致看一下Laravel中如何对日志进行配置以及日志的简单使用. 1.日志处理器配置 首先我们来看日志处理器的配置.Laravel目前支持四种日志处理器: single -- 将日志记录到单个文件中.该日志处理器对应Monolog的StreamHandler. daily -- 以日期为单位将日志进行归档,每天创建一个新的日志文件记录日志.该

日志传送配置成功,但备份日志作业过不去,求大神解

问题描述 日志传送配置成功,但备份日志作业过不去,求大神解 日志传送配置成功,但每次备份日志作业过不去,求大神解. (新人驾到木有赏,求好心人支持!) 下图是报错记录 解决方案 http://wenku.baidu.com/link?url=GmOfjW3uv3OmB0HqmibzgpUzTkJLnARr2UFHFIFhwbbHw2rzfm890-gsj0sbDdAQZIHO4a7S3Y9eIL96ONbt2IbhgM1emJdOPmXWdE_owjO

Mac电脑怎么查看配置?

Mac电脑怎么查看配置?   第一步: 打开苹果电脑后,点击屏幕左上角苹果图标,在下拉菜单中,点击选择"关于本机" 第二步: 在关于本机界面,就可以看到电脑的系统版本,以及硬件的简略信息了. 第三步: 再点击底部"系统报告"按钮,就可以查看更详细的系统软.硬件配置信息了.               更多精彩内容请关注三联电脑常识栏目

Windows Vista系统中的日志查看器功能介绍

当我们的Windows 系统出现问题时,要分析与定位故障,最简单的办法莫过于使用事件查看器,如Windows XP中的事件查看器可以让我们分析系统日志.应用程序日志与安全性日志,以从中找出可能存在问题的线索.不过,客观地说来,之前Windows版本包括Windows XP中的事件查看器在使用中存在很多不足,很多时候所给出的信息呆板.含糊,不足以让我们准确地定位可能发生的故障,而当待找的信息淹没在大量的事件之中时,简陋的事件过滤与查询机制往往让我们很难快速找到与定位. 在Windows Vista

安卓网络请求Retrofit2怎么配置service

问题描述 安卓网络请求Retrofit2怎么配置service 如上图这样的post接口怎么在RetrofitService配置 public interface RetrofitService { @FormUrlEncoded @POST Call<> }

日志查看审计程序

日志查看审计程序,尚未完成,初步设想见设计图         Python代码   Auditlog   Help      $ auditlog   Usage:      Homepage: http://netkiller.github.com     Author: Neo <netkiller@msn.com>      Options:     -h, --help            show this help message and exit     -d, --daemo