Print Configuration log level Feign

A log level configuration Feign fine-grained (micro configured for each service)

 1, java code embodied

       (1) arranged in the interface annotation above configuration Feign 

/**
 * @author : maybesuch
 * @version : 1.0
 * @Description : 用户中心Feign接口
 * @Date : 2020/1/9 11:43
 * @Copyright : Copyright (c) 2020 All Rights Reserved
 **/
@FeignClient(value = "user-center", configuration = UserCenterFeignConfiguration.class)
public interface UserCenterFeignClient {

    @GetMapping("/users/{id}")
    UserDTO findById(@PathVariable("id") Integer id);

}

    (2) define the configuration content, that is, feign log level

            Logger There are four types: NONE(默认), , BASIC, HEADERS, FULLto set the logging level by registering Bean

            Note: do not need on this method @Configuration annotations, otherwise it will be all FeignClient share, if you add a comment, you need to put such a scan can not start package

/ ** 
 * @author : maybesuch 
 * @version : 1.0 
 * @Description: user definition request log level of the center Feign 
 * @date: 2020/1/9 17:24 
 * @Copyright: Copyright (C) 2020 All Rights Reserved 
 * * / 
public  class UserCenterFeignConfiguration { 

    @Bean 
    Logger.Level feignLoggerLevel () { 
        // set the log 
        return Logger.Level.FULL; 
    } 
}

     (3) the full path of Feign arranged in application.yml 

logging:
  level:
#    com.maybesuch.contentcenter.feignclient.UserCenterFeignClient: debug
    com.maybesuch: debug

 

    2, the profile of the way

        Just add the configuration in application.yml:   

logging: 
  Level: 
#     com.maybesuch.contentcenter.feignclient.UserCenterFeignClient: Debug 
    com.maybesuch: Debug 

Feign: 
  Client: 
    config: 
      # to call the name of the service 
      user- Center: 
        loggerLevel: Full

 

Second, the global log level configuration

    1, java code way

     (1) starting class @EnableFeignClients arranged on annotation defaultConfiguration 

@SpringBootApplication
@EnableFeignClients(defaultConfiguration = GlobalFeignConfiguration.class)
public class ContentCenterApplication {

    public static void main(String[] args) {
        SpringApplication.run(ContentCenterApplication.class, args);
    }
}

    (2) the definition of GlobalFeignConfiguration class, which does not need @Configuration comment

/ ** 
 * @author : maybesuch 
 * @version : 1.0 
 * @Description: Feign define the global logging level 
 * @date: 2020/1/9 17:24 
 * @Copyright: Copyright (C) 2020 All Rights Reserved 
 * * / 
public  class GlobalFeignConfiguration { 

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

    (3) profiles application.yml the need to configure the log level can only print out call log information Feign

logging:
  level:
    com.maybesuch: debug

 

2, the configuration file mode

   Just add the configuration in application.yml:

logging: 
  Level: 
    com.maybecare: Debug 

Feign: 
  Client: 
    config: 
      # Feign global log level 
      default: 
        loggerLevel: Full

 

Log Print Results:

c.m.c.feignclient.UserCenterFeignClient  : [UserCenterFeignClient#findById] ---> GET http://user-center/users/1 HTTP/1.1
c.m.c.feignclient.UserCenterFeignClient  : [UserCenterFeignClient#findById] ---> END HTTP (0-byte body)
c.m.c.feignclient.UserCenterFeignClient  : [UserCenterFeignClient#findById] <--- HTTP/1.1 200  (17ms)
c.m.c.feignclient.UserCenterFeignClient  : [UserCenterFeignClient#findById] content-type: application/json;charset=UTF-8
c.m.c.feignclient.UserCenterFeignClient  : [UserCenterFeignClient#findById] date: Fri, 10 Jan 2020 05:33:40 GMT
c.m.c.feignclient.UserCenterFeignClient  : [UserCenterFeignClient#findById] transfer-encoding: chunked
c.m.c.feignclient.UserCenterFeignClient  : [UserCenterFeignClient#findById] 
c.m.c.feignclient.UserCenterFeignClient  : [UserCenterFeignClient#findById] {"id":1,"bane":"maybesuch"}
c.m.c.feignclient.UserCenterFeignClient  : [UserCenterFeignClient#findById] <--- END HTTP (161-byte body)

Guess you like

Origin www.cnblogs.com/maybesuch/p/12175002.html