관리 메뉴

IT.FARMER

open feign log 설정 본문

Spring/Spring Cloud

open feign log 설정

아이티.파머 2022. 1. 14. 11:14
반응형

open feign을 사용하면서 Request,Response 에대한 header,body, parameter 를 확인 하고 싶을 것이다. 이때 로깅레벨을 변경 해주고 @FeignClient 가 있는 package 의 레벨을 debug 로 변경해주면 해당 로그를 볼수 있다.

@Configuration
public class GlobalCustomFeignConfig {

    /**
     * 기본 설정이 NON 으로 FULL 로 지정하여 request, response, header,body, metadata 모두를 로깅한다.
     * 로그 설정에서 @Feign package 를 debug level로 변경해 준다.
     */
    @Bean
    Logger.Level loggerLevel() {
        return Logger.Level.FULL;
    }

}
  • loggerLevel : NONE, BASIC, HEADER, FULL을 지정할 수 있음
    • NONE : default, 로그를 남기지 않음
    • BASIC : Request Method, URL과 응답 코드, 실행 시간을 남김
    • HEADERS : BASIC의 정보를 포함하여, 요청, 응답의 헤더를 남김
    • FULL : 요청, 응답의 header, body, metadata를 남김
    • logging.level.com.example.demo.PostClient: debug 등의 debug logger 설정이 되어 있어야함
  • encoder, decode : body의 내용을 Object로 변경하는 class 지정, 각각
  • retryer : 요청이 실패했을 때 재시도에 대한 정책
logging:
  level:
    root: info
    ads.client: debug # open feign package 로그를 보기 위함.
    com.client.external: debug

Logs

2022-01-10 17:11:32.327  INFO 80042 --- [p-nio-80-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
2022-01-10 17:11:32.327  INFO 80042 --- [p-nio-80-exec-1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2022-01-10 17:11:32.329  INFO 80042 --- [p-nio-80-exec-1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 2 ms
2022-01-10 17:11:32.383 DEBUG 80042 --- [pool-1-thread-1] com.client.external.FallbackClient       : [FallbackClient#exception] ---> GET http://localhost:8083/product/exception HTTP/1.1
2022-01-10 17:11:32.384 DEBUG 80042 --- [pool-1-thread-1] com.client.external.FallbackClient       : [FallbackClient#exception] ---> END HTTP (0-byte body)
2022-01-10 17:11:32.580 DEBUG 80042 --- [pool-1-thread-1] com.client.external.FallbackClient       : [FallbackClient#exception] <--- HTTP/1.1 200 OK (193ms)
2022-01-10 17:11:32.580 DEBUG 80042 --- [pool-1-thread-1] com.client.external.FallbackClient       : [FallbackClient#exception] content-length: 18
2022-01-10 17:11:32.580 DEBUG 80042 --- [pool-1-thread-1] com.client.external.FallbackClient       : [FallbackClient#exception] content-type: text/plain;charset=UTF-8
2022-01-10 17:11:32.580 DEBUG 80042 --- [pool-1-thread-1] com.client.external.FallbackClient       : [FallbackClient#exception] 
2022-01-10 17:11:32.582 DEBUG 80042 --- [pool-1-thread-1] com.client.external.FallbackClient       : [FallbackClient#exception] no exception occur
2022-01-10 17:11:32.582 DEBUG 80042 --- [pool-1-thread-1] com.client.external.FallbackClient       : [FallbackClient#exception] <--- END HTTP (18-byte body)
반응형

'Spring > Spring Cloud' 카테고리의 다른 글

open feign error decoder custom  (0) 2022.01.14
spring open feign 예제  (0) 2022.01.14
Spring Open Feign  (0) 2022.01.14
circuit breaker (hystrix and the resilience4j)  (0) 2021.07.21
Netflix OSS(eureka, Hystrix , zull, ribbon)  (0) 2021.07.21