From f738bbfba7a9da0da11edb5f270ad4538bec0a9f Mon Sep 17 00:00:00 2001 From: Colt Date: Fri, 28 Oct 2022 20:26:17 +0900 Subject: [PATCH] =?UTF-8?q?feat=20:=20Logger=20=EC=84=A4=EC=A0=95=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../configuration/FeignConfiguration.kt | 41 +++++++++++++++++++ .../src/main/resources/application.yaml | 6 ++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/놀이터(예제 코드 작성)/spring-cloud-open-feign/src/main/kotlin/com/banjjoknim/springcloudopenfeign/configuration/FeignConfiguration.kt b/놀이터(예제 코드 작성)/spring-cloud-open-feign/src/main/kotlin/com/banjjoknim/springcloudopenfeign/configuration/FeignConfiguration.kt index 02a1512..46b2c9c 100644 --- a/놀이터(예제 코드 작성)/spring-cloud-open-feign/src/main/kotlin/com/banjjoknim/springcloudopenfeign/configuration/FeignConfiguration.kt +++ b/놀이터(예제 코드 작성)/spring-cloud-open-feign/src/main/kotlin/com/banjjoknim/springcloudopenfeign/configuration/FeignConfiguration.kt @@ -1,7 +1,9 @@ package com.banjjoknim.springcloudopenfeign.configuration import com.fasterxml.jackson.databind.DeserializationFeature +import feign.Logger import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer +import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder @@ -13,3 +15,42 @@ class FeignConfiguration : Jackson2ObjectMapperBuilderCustomizer { .featuresToDisable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) } } + +/** + * For each Feign client, a logger is created by default. + * + * To enable logging, we should declare it in the application.properties file using the package name of the client interfaces: + * + * > logging.level.com.baeldung.cloud.openfeign.client: DEBUG + * + * Or, if we want to enable logging only for one particular client in a package, we can use the full class name: + * + * > logging.level.com.baeldung.cloud.openfeign.client.JSONPlaceHolderClient: DEBUG + * + * **Note that Feign logging responds only to the DEBUG level.** + * + * The ***Logger.Level*** that we may configure per client indicates how much to log: + * ```java + * public class ClientConfiguration { + * + * @Bean + * Logger.Level feignLoggerLevel() { + * return Logger.Level.BASIC; + * } + * } + * ``` + * + * There are four logging levels to choose from: + * + * - NONE – no logging, which is the default + * - BASIC – log only the request method, URL and response status + * - HEADERS – log the basic information together with request and response headers + * - FULL – log the body, headers and metadata for both request and response + */ +@Configuration +class LoggerConfiguration { + @Bean + fun feignLoggerLevel(): Logger.Level { + return Logger.Level.FULL + } +} diff --git a/놀이터(예제 코드 작성)/spring-cloud-open-feign/src/main/resources/application.yaml b/놀이터(예제 코드 작성)/spring-cloud-open-feign/src/main/resources/application.yaml index bd53c9b..1969158 100644 --- a/놀이터(예제 코드 작성)/spring-cloud-open-feign/src/main/resources/application.yaml +++ b/놀이터(예제 코드 작성)/spring-cloud-open-feign/src/main/resources/application.yaml @@ -14,4 +14,8 @@ spring: physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl implicit-strategy: org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl show-sql: true - +logging: + level: + com: + banjjoknim: + springcloudopenfeign: DEBUG