OpenFeign日志打印功能


  1. 建一个FeignConfig,如下:

    @Configuration
    public class FeignConfig {
    
        @Bean
        Logger.Level feignLoggerLevel() {
            // 日志级别:NONE、BASIC、HEADERS、FULL
            return Logger.Level.FULL;
        }
    
    }
    
  2. 在application.yml配置文件中添加如下配置:

    logging:
      level:
      	# feign日志以什么级别监控哪个接口
        com.athailin.springcloud.service.PaymentFeignService: debug
    
  3. 日志打印效果:

    2021-08-19 10:40:45.490 DEBUG 50600 --- [p-nio-80-exec-2] c.a.s.service.PaymentFeignService        : [PaymentFeignService#getPaymentById] ---> GET http://CLOUD-PAYMENT-SERVICE/payment/get/1 HTTP/1.1
    2021-08-19 10:40:45.490 DEBUG 50600 --- [p-nio-80-exec-2] c.a.s.service.PaymentFeignService        : [PaymentFeignService#getPaymentById] ---> END HTTP (0-byte body)
    2021-08-19 10:40:45.499 DEBUG 50600 --- [p-nio-80-exec-2] c.a.s.service.PaymentFeignService        : [PaymentFeignService#getPaymentById] <--- HTTP/1.1 200 (8ms)
    2021-08-19 10:40:45.499 DEBUG 50600 --- [p-nio-80-exec-2] c.a.s.service.PaymentFeignService        : [PaymentFeignService#getPaymentById] connection: keep-alive
    2021-08-19 10:40:45.499 DEBUG 50600 --- [p-nio-80-exec-2] c.a.s.service.PaymentFeignService        : [PaymentFeignService#getPaymentById] content-type: application/json
    2021-08-19 10:40:45.500 DEBUG 50600 --- [p-nio-80-exec-2] c.a.s.service.PaymentFeignService        : [PaymentFeignService#getPaymentById] date: Thu, 19 Aug 2021 02:40:45 GMT
    2021-08-19 10:40:45.500 DEBUG 50600 --- [p-nio-80-exec-2] c.a.s.service.PaymentFeignService        : [PaymentFeignService#getPaymentById] keep-alive: timeout=60
    2021-08-19 10:40:45.500 DEBUG 50600 --- [p-nio-80-exec-2] c.a.s.service.PaymentFeignService        : [PaymentFeignService#getPaymentById] transfer-encoding: chunked
    2021-08-19 10:40:45.500 DEBUG 50600 --- [p-nio-80-exec-2] c.a.s.service.PaymentFeignService        : [PaymentFeignService#getPaymentById] 
    2021-08-19 10:40:45.500 DEBUG 50600 --- [p-nio-80-exec-2] c.a.s.service.PaymentFeignService        : [PaymentFeignService#getPaymentById] {"code":200,"message":"查询成功!serverPort:8001","data":{"id":1,"serial":"aaabb01"}}
    2021-08-19 10:40:45.500 DEBUG 50600 --- [p-nio-80-exec-2] c.a.s.service.PaymentFeignService        : [PaymentFeignService#getPaymentById] <--- END HTTP (90-byte body)
    
Java
  • 作者:周海林(联系作者)
  • 发表时间:2021-10-29
  • 版权声明:自由转载-非商用-非衍生-周海林贼帅
  • 加作者微信:请在文末添加作者微信

评论