欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

使用Feign?logging?開啟調(diào)用日志

 更新時間:2022年06月16日 10:08:49   作者:西蒙老爺  
這篇文章主要介紹了使用Feign?logging?開啟調(diào)用日志,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教

Feign logging開啟調(diào)用日志

application.yml 配置

logging:
  level:
    yourproject.userClient: debug

FeignConfiguration

@Configuration
public class FeignConfiguration {
    @Bean
    Logger.Level feignLoggerLevel() {
        return Logger.Level.FULL;
    }
}

效果


參考官方:http://cloud.spring.io/spring-cloud-openfeign/single/spring-cloud-openfeign.html#_feign_logging

Feign啟用日志

需求

想追蹤Feign客戶端發(fā)送的數(shù)據(jù).

Feign在構(gòu)建被@FeignClient注解修飾的服務客戶端時,會為每一個客戶端都創(chuàng)建一個feign.Logger實例,這樣就可以利用該日志對象的DEBUG模式來幫助分析Feign的請求細節(jié)。

實現(xiàn)步驟

1. 在application.yml中使用 logging.level.<Feign客戶端對應的接口的全限定名> 的參數(shù)配置格式來開啟指定客戶端日志. 

logging:
? level:
? ? com:
? ? ? yc:
? ? ? ? springcloud2:
? ? ? ? ? service:
? ? ? ? ? ? IProductClientService: DEBUG ? #注意這里是Feign客戶端接口的完整路徑,這是我們要監(jiān)控日志的接口

2. 但由于Feign客戶端默認的Logger.Level對象定義為NONE級別,因此需要對它進行調(diào)整.  Logger.Level的源碼中規(guī)定了以下幾個級別:

  public enum Level {
    // 不記錄日志 (默認)。
    NONE,
    //只記錄請求方法和URL以及響應狀態(tài)代碼和執(zhí)行時間
    BASIC,
    //記錄請求和應答的頭的基本信息
    HEADERS,
    //記錄請求和響應的頭信息,正文和元數(shù)據(jù)
    FULL
  }

那么如何將級別從NONE修改過來呢?這里有兩種方式:

1. 全局配置: 在應用主配置類中加入 Logger.Level的Bean的創(chuàng)建和托管,這里這個應用中所有的Feign客戶端都會按這個日志級別. 

@SpringBootConfiguration
public class FeignLogConfig {
    @Bean
    Logger.Level feignLoggerLevel(){
        return Logger.Level.FULL;
    }
}

運行 程序 [microservice-consumer-feign],查看輸出結(jié)果。 

2020-10-16 15:14:45.634 DEBUG 15604 --- [nio-9999-exec-1] c.y.s.service.IProductClientService      : [IProductClientService#listProduct] <--- HTTP/1.1 200 (799ms)
2020-10-16 15:14:45.634 DEBUG 15604 --- [nio-9999-exec-1] c.y.s.service.IProductClientService      : [IProductClientService#listProduct] cache-control: no-cache, no-store, max-age=0, must-revalidate
2020-10-16 15:14:45.634 DEBUG 15604 --- [nio-9999-exec-1] c.y.s.service.IProductClientService      : [IProductClientService#listProduct] connection: keep-alive
2020-10-16 15:14:45.634 DEBUG 15604 --- [nio-9999-exec-1] c.y.s.service.IProductClientService      : [IProductClientService#listProduct] content-type: application/json;charset=UTF-8
2020-10-16 15:14:45.634 DEBUG 15604 --- [nio-9999-exec-1] c.y.s.service.IProductClientService      : [IProductClientService#listProduct] date: Fri, 16 Oct 2020 07:14:45 GMT
2020-10-16 15:14:45.634 DEBUG 15604 --- [nio-9999-exec-1] c.y.s.service.IProductClientService      : [IProductClientService#listProduct] expires: 0
2020-10-16 15:14:45.634 DEBUG 15604 --- [nio-9999-exec-1] c.y.s.service.IProductClientService      : [IProductClientService#listProduct] keep-alive: timeout=60
2020-10-16 15:14:45.634 DEBUG 15604 --- [nio-9999-exec-1] c.y.s.service.IProductClientService      : [IProductClientService#listProduct] pragma: no-cache
2020-10-16 15:14:45.634 DEBUG 15604 --- [nio-9999-exec-1] c.y.s.service.IProductClientService      : [IProductClientService#listProduct] transfer-encoding: chunked
2020-10-16 15:14:45.634 DEBUG 15604 --- [nio-9999-exec-1] c.y.s.service.IProductClientService      : [IProductClientService#listProduct] x-content-type-options: nosniff
2020-10-16 15:14:45.634 DEBUG 15604 --- [nio-9999-exec-1] c.y.s.service.IProductClientService      : [IProductClientService#listProduct] x-frame-options: DENY
2020-10-16 15:14:45.634 DEBUG 15604 --- [nio-9999-exec-1] c.y.s.service.IProductClientService      : [IProductClientService#listProduct] x-xss-protection: 1; mode=block
2020-10-16 15:14:45.635 DEBUG 15604 --- [nio-9999-exec-1] c.y.s.service.IProductClientService      : [IProductClientService#listProduct] 
2020-10-16 15:14:45.636 DEBUG 15604 --- [nio-9999-exec-1] c.y.s.service.IProductClientService      : [IProductClientService#listProduct] [{"productId":1,"productName":"a","productDesc":"good"}]
2020-10-16 15:14:45.637 DEBUG 15604 --- [nio-9999-exec-1] c.y.s.service.IProductClientService      : [IProductClientService#listProduct] <--- END HTTP (56-byte body)

2. 針對一個具體的Feign客戶端單獨配置.  比如這里對一個Feign客戶端進行日志配置. 

@Configuration
public class FeignClientConfig {
    //加入安全配置
    @Bean
    public BasicAuthRequestInterceptor getBasicAuthRequestInterceptor(){
        return new BasicAuthRequestInterceptor("admin","a");
    }
 
    @Bean
    Logger.Level feignLoggerLevel(){
        return Logger.Level.FULL;
    }
}

重啟應用程序,查看輸出:

2020-10-16 15:20:21.856 DEBUG 15620 --- [nio-9999-exec-1] c.y.s.service.IProductClientService      : [IProductClientService#listProduct] <--- HTTP/1.1 200 (476ms)
2020-10-16 15:20:21.856 DEBUG 15620 --- [nio-9999-exec-1] c.y.s.service.IProductClientService      : [IProductClientService#listProduct] cache-control: no-cache, no-store, max-age=0, must-revalidate
2020-10-16 15:20:21.856 DEBUG 15620 --- [nio-9999-exec-1] c.y.s.service.IProductClientService      : [IProductClientService#listProduct] connection: keep-alive
2020-10-16 15:20:21.856 DEBUG 15620 --- [nio-9999-exec-1] c.y.s.service.IProductClientService      : [IProductClientService#listProduct] content-type: application/json;charset=UTF-8
2020-10-16 15:20:21.856 DEBUG 15620 --- [nio-9999-exec-1] c.y.s.service.IProductClientService      : [IProductClientService#listProduct] date: Fri, 16 Oct 2020 07:20:21 GMT
2020-10-16 15:20:21.856 DEBUG 15620 --- [nio-9999-exec-1] c.y.s.service.IProductClientService      : [IProductClientService#listProduct] expires: 0
2020-10-16 15:20:21.856 DEBUG 15620 --- [nio-9999-exec-1] c.y.s.service.IProductClientService      : [IProductClientService#listProduct] keep-alive: timeout=60
2020-10-16 15:20:21.856 DEBUG 15620 --- [nio-9999-exec-1] c.y.s.service.IProductClientService      : [IProductClientService#listProduct] pragma: no-cache
2020-10-16 15:20:21.856 DEBUG 15620 --- [nio-9999-exec-1] c.y.s.service.IProductClientService      : [IProductClientService#listProduct] transfer-encoding: chunked
2020-10-16 15:20:21.857 DEBUG 15620 --- [nio-9999-exec-1] c.y.s.service.IProductClientService      : [IProductClientService#listProduct] x-content-type-options: nosniff
2020-10-16 15:20:21.857 DEBUG 15620 --- [nio-9999-exec-1] c.y.s.service.IProductClientService      : [IProductClientService#listProduct] x-frame-options: DENY
2020-10-16 15:20:21.857 DEBUG 15620 --- [nio-9999-exec-1] c.y.s.service.IProductClientService      : [IProductClientService#listProduct] x-xss-protection: 1; mode=block
2020-10-16 15:20:21.857 DEBUG 15620 --- [nio-9999-exec-1] c.y.s.service.IProductClientService      : [IProductClientService#listProduct] 
2020-10-16 15:20:21.859 DEBUG 15620 --- [nio-9999-exec-1] c.y.s.service.IProductClientService      : [IProductClientService#listProduct] [{"productId":1,"productName":"a","productDesc":"good"}]
2020-10-16 15:20:21.859 DEBUG 15620 --- [nio-9999-exec-1] c.y.s.service.IProductClientService      : [IProductClientService#listProduct] <--- END HTTP (56-byte body)

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關文章

  • kettle中使用js調(diào)用java類的方法

    kettle中使用js調(diào)用java類的方法

    這篇文章主要介紹了kettle中使用js調(diào)用java類的方法,本文講解了注意事項和調(diào)用語法,需要的朋友可以參考下
    2015-05-05
  • Spring切入點表達式配置過程圖解

    Spring切入點表達式配置過程圖解

    這篇文章主要介紹了Spring切入點表達式配置過程圖解,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2020-08-08
  • Java?導出?CSV?文件操作詳情

    Java?導出?CSV?文件操作詳情

    這篇文章主要介紹了Java導出CSV文件操作詳情,文章通過導入坐標展開詳細內(nèi)容介紹,具有一定的參考價值,需要的小伙伴可以參考一下
    2022-08-08
  • 詳解SpringBoot中@NotNull,@NotBlank注解使用

    詳解SpringBoot中@NotNull,@NotBlank注解使用

    這篇文章主要為大家詳細介紹了Spring?Boot中集成Validation與@NotNull,@NotBlank等注解的簡單使用,感興趣的小伙伴可以跟隨小編一起學習一下
    2022-08-08
  • SpringBoot中的Actuator詳解

    SpringBoot中的Actuator詳解

    這篇文章主要介紹了SpringBoot中的Actuator詳解,Spring Boot Actuator 在Spring Boot第一個版本發(fā)布的時候就有了,它為Spring Boot提供了一系列產(chǎn)品級的特性,監(jiān)控應用程序,收集元數(shù)據(jù),運行情況或者數(shù)據(jù)庫狀態(tài)等,需要的朋友可以參考下
    2023-09-09
  • java 判斷l(xiāng)ist是否為空過程解析

    java 判斷l(xiāng)ist是否為空過程解析

    這篇文章主要介紹了java 判斷l(xiāng)ist是否為空過程解析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2019-09-09
  • 解決mybatis 執(zhí)行mapper的方法時報空指針問題

    解決mybatis 執(zhí)行mapper的方法時報空指針問題

    這篇文章主要介紹了解決mybatis 執(zhí)行mapper的方法時報空指針問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-07-07
  • FastJSON的0day漏洞的解決

    FastJSON的0day漏洞的解決

    本文主要介紹了FastJSON的0day漏洞的解決,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2023-05-05
  • Java使用Soap方式調(diào)用WebService接口代碼示例

    Java使用Soap方式調(diào)用WebService接口代碼示例

    Java調(diào)用WebService接口是指通過Java語言來訪問并與WebService進行交互,WebService是一種基于Web的服務架構(gòu),它通過標準的XML和HTTP協(xié)議來提供服務,這篇文章主要給大家介紹了關于Java使用Soap方式調(diào)用WebService接口的相關資料,需要的朋友可以參考下
    2024-03-03
  • java同步之volatile解析

    java同步之volatile解析

    volatile可以說是Java虛擬機提供的最輕量級的同步機制了,了解volatile的語義對理解多線程的特性具有很重要的意義,下面小編帶大家一起學習一下
    2019-05-05

最新評論