From a5a543a4305beaa80bf0e42c67fa3cb3dbf83a31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=95=88=EC=9C=A0=EC=A7=84?= Date: Sun, 22 Oct 2023 16:23:28 +0900 Subject: [PATCH 01/10] =?UTF-8?q?add:=20logback=20=EC=84=A4=EC=A0=95=20?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - logback-spring.xml - console-appender.xml - file-appender.xml - aws-appender.xml --- src/main/resources/aws-appender.xml | 18 +++++ src/main/resources/console-appender.xml | 0 src/main/resources/file-appender.xml | 0 src/main/resources/logback-spring.xml | 99 +++++++++++++++++++++++++ 4 files changed, 117 insertions(+) create mode 100644 src/main/resources/aws-appender.xml create mode 100644 src/main/resources/console-appender.xml create mode 100644 src/main/resources/file-appender.xml create mode 100644 src/main/resources/logback-spring.xml diff --git a/src/main/resources/aws-appender.xml b/src/main/resources/aws-appender.xml new file mode 100644 index 00000000..6ca27229 --- /dev/null +++ b/src/main/resources/aws-appender.xml @@ -0,0 +1,18 @@ + + + + ERROR + + + %d{yyyyMMdd'T'HHmmss} %thread %level %logger{15} %msg%n + + + katj-dev + error- + ap-northeast-2 + 50 + 30000 + 5000 + 0 + + \ No newline at end of file diff --git a/src/main/resources/console-appender.xml b/src/main/resources/console-appender.xml new file mode 100644 index 00000000..e69de29b diff --git a/src/main/resources/file-appender.xml b/src/main/resources/file-appender.xml new file mode 100644 index 00000000..e69de29b diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-spring.xml new file mode 100644 index 00000000..41436e8a --- /dev/null +++ b/src/main/resources/logback-spring.xml @@ -0,0 +1,99 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 99ae4d10b8d7abf90d4498d6d5433d29d9892355 Mon Sep 17 00:00:00 2001 From: ktony Date: Tue, 24 Oct 2023 19:16:37 +0900 Subject: [PATCH 02/10] =?UTF-8?q?update:=20AWS=20log=20=EC=9D=98=EC=A1=B4?= =?UTF-8?q?=EC=84=B1=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit AWS cloudwatch에 로그 전송 의존성 추가 --- build.gradle.kts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/build.gradle.kts b/build.gradle.kts index a5761424..b4373ea0 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -27,10 +27,13 @@ dependencies { implementation("org.springframework.boot:spring-boot-starter-data-jpa") implementation("org.springframework.boot:spring-boot-starter-web") implementation("org.springframework.boot:spring-boot-starter-validation") + implementation("org.springframework.boot:spring-boot-starter-logging") implementation("com.fasterxml.jackson.module:jackson-module-kotlin") implementation("org.jetbrains.kotlin:kotlin-reflect") implementation("org.springframework.boot:spring-boot-starter-aop") + implementation(group = "ca.pjer", name = "logback-awslogs-appender", version = "1.6.0") + // 스케줄링 처리를 위한 코루틴 라이브러리 추가 implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0") From f0a459b01561a96a0701d3fb7bcc4f57ba65ab15 Mon Sep 17 00:00:00 2001 From: ktony Date: Tue, 24 Oct 2023 19:19:18 +0900 Subject: [PATCH 03/10] =?UTF-8?q?add:=20logback-dev.properties=20=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit logback 관련 xml 파일들에서 사용 할 변수 설정 --- src/main/resources/logs/logback-dev.properties | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/main/resources/logs/logback-dev.properties diff --git a/src/main/resources/logs/logback-dev.properties b/src/main/resources/logs/logback-dev.properties new file mode 100644 index 00000000..b3bdd2de --- /dev/null +++ b/src/main/resources/logs/logback-dev.properties @@ -0,0 +1,11 @@ +log.config.savemode=LOG +log.config.packagename=katj.study.springboot +log.config.mode=dev +log.config.path=logs/dev +log.config.default.filename=katj-dev +log.config.min=1 +log.config.max=10 +log.config.filesizezip=10MB +log.config.days=10 +log.config.filesizelog=100MB +log.config.totalfilesize=10GB \ No newline at end of file From 0636838fe8dd5b02eb1fb9d8444e2ed75a5bb8da Mon Sep 17 00:00:00 2001 From: ktony Date: Tue, 24 Oct 2023 19:20:03 +0900 Subject: [PATCH 04/10] =?UTF-8?q?add:=20MDC=20=EB=A1=9C=EA=B9=85=20?= =?UTF-8?q?=ED=95=84=ED=84=B0=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 필터를 사용하여 사용자 요청/응답 까지의 로그를 uuid로 그룹핑 --- .../katj/util/log/MDCRequestLoggingFilter.kt | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/main/kotlin/com/hh2/katj/util/log/MDCRequestLoggingFilter.kt diff --git a/src/main/kotlin/com/hh2/katj/util/log/MDCRequestLoggingFilter.kt b/src/main/kotlin/com/hh2/katj/util/log/MDCRequestLoggingFilter.kt new file mode 100644 index 00000000..c690b04e --- /dev/null +++ b/src/main/kotlin/com/hh2/katj/util/log/MDCRequestLoggingFilter.kt @@ -0,0 +1,23 @@ +package com.hh2.katj.util.log + +import jakarta.servlet.Filter +import jakarta.servlet.FilterChain +import jakarta.servlet.ServletRequest +import jakarta.servlet.ServletResponse +import org.slf4j.MDC +import org.springframework.core.Ordered +import org.springframework.core.annotation.Order +import org.springframework.stereotype.Component +import java.util.UUID + +@Component +@Order(Ordered.HIGHEST_PRECEDENCE) +class MDCRequestLoggingFilter : Filter { + override fun doFilter(request: ServletRequest, response: ServletResponse, chain: FilterChain) { + val uuid = UUID.randomUUID() + MDC.put("request_id", uuid.toString()) + chain.doFilter(request,response) + MDC.clear() + } + +} \ No newline at end of file From ed298b3adce081273bcd91f78dbcb5a063855e66 Mon Sep 17 00:00:00 2001 From: ktony Date: Tue, 24 Oct 2023 19:22:40 +0900 Subject: [PATCH 05/10] =?UTF-8?q?update:=20logback=20=EA=B4=80=EB=A0=A8=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit aws, console, file별로 로그를 남기는 xml 파일의 상세 내용 수정 --- src/main/resources/aws-appender.xml | 2 +- src/main/resources/console-appender.xml | 10 +++ src/main/resources/file-appender.xml | 75 +++++++++++++++++++++ src/main/resources/logback-spring.xml | 88 ++++--------------------- 4 files changed, 98 insertions(+), 77 deletions(-) diff --git a/src/main/resources/aws-appender.xml b/src/main/resources/aws-appender.xml index 6ca27229..30a74302 100644 --- a/src/main/resources/aws-appender.xml +++ b/src/main/resources/aws-appender.xml @@ -4,7 +4,7 @@ ERROR - %d{yyyyMMdd'T'HHmmss} %thread %level %logger{15} %msg%n + %d{yyyyMMdd'T'HHmmss} [%thread] [%level] [%X{request_id}] [%logger{15}] %msg%n katj-dev diff --git a/src/main/resources/console-appender.xml b/src/main/resources/console-appender.xml index e69de29b..1e9e46cc 100644 --- a/src/main/resources/console-appender.xml +++ b/src/main/resources/console-appender.xml @@ -0,0 +1,10 @@ + + + + + + + ${LOG_PATTERN_DEFAULT} + + + \ No newline at end of file diff --git a/src/main/resources/file-appender.xml b/src/main/resources/file-appender.xml index e69de29b..74ad8df0 100644 --- a/src/main/resources/file-appender.xml +++ b/src/main/resources/file-appender.xml @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + + + + + + + + ERROR + NEUTRAL + DENY + + ${LOG_PATH}/${LOG_FILE_NAME}-error.log + + ${LOG_PATH}/${LOG_FILE_NAME}-error.%d{yyyy-MM-dd}_%i.log + + + 10MB + + + + 30 + + + 1 + 10 + + + + ${LOG_PATTERN_DEFAULT} + + + + + INFO + ACCEPT + DENY + + ${LOG_PATH}/${LOG_FILE_NAME}-info.log + + ${LOG_PATH}/${LOG_FILE_NAME}-info.%d{yyyy-MM-dd}_%i.log + + + 10MB + + + + 30 + + + 1 + 10 + + + + ${LOG_PATTERN_DEFAULT} + + + \ No newline at end of file diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-spring.xml index 41436e8a..4929e2b2 100644 --- a/src/main/resources/logback-spring.xml +++ b/src/main/resources/logback-spring.xml @@ -1,76 +1,5 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -79,21 +8,28 @@ - + + - + + - + + + + + + - + \ No newline at end of file From 874062d45f0c1159b1e234ed35ff4aa8ae8e8362 Mon Sep 17 00:00:00 2001 From: ktony Date: Tue, 24 Oct 2023 20:39:46 +0900 Subject: [PATCH 06/10] update: Exception -> RuntimeException --- .../com/hh2/katj/favorite/component/FavoriteManager.kt | 8 ++++---- .../hh2/katj/payment/component/PaymentMethodManager.kt | 8 ++++---- .../kotlin/com/hh2/katj/trip/component/TripManager.kt | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/kotlin/com/hh2/katj/favorite/component/FavoriteManager.kt b/src/main/kotlin/com/hh2/katj/favorite/component/FavoriteManager.kt index 3d8f1a96..1ea8c2f2 100644 --- a/src/main/kotlin/com/hh2/katj/favorite/component/FavoriteManager.kt +++ b/src/main/kotlin/com/hh2/katj/favorite/component/FavoriteManager.kt @@ -33,7 +33,7 @@ class FavoriteManager ( try { findFavorite.update(request) } catch (e: Exception) { - throw Exception(INTERNAL_SERVER_ERROR_FROM_DATABASE.name) + throw RuntimeException(INTERNAL_SERVER_ERROR_FROM_DATABASE.name) } return findFavorite @@ -47,7 +47,7 @@ class FavoriteManager ( try { favoriteRepository.delete(deleteFavorite) } catch (e: Exception) { - throw Exception(INTERNAL_SERVER_ERROR_FROM_DATABASE.name) + throw RuntimeException(INTERNAL_SERVER_ERROR_FROM_DATABASE.name) } return true @@ -59,7 +59,7 @@ class FavoriteManager ( try { favoriteRepository.deleteAllByUserId(userId) } catch (e: Exception) { - throw Exception(INTERNAL_SERVER_ERROR_FROM_DATABASE.name) + throw RuntimeException(INTERNAL_SERVER_ERROR_FROM_DATABASE.name) } return true @@ -71,7 +71,7 @@ class FavoriteManager ( val deleteRowCount = favoriteRepository.deleteFavoritesByUserIdAndIdIn(userId, deleteFavoriteIds) if (deleteRowCount != deleteFavoriteIds.size) { - throw Exception(INTERNAL_SERVER_ERROR_FROM_DATABASE.name) + throw RuntimeException(INTERNAL_SERVER_ERROR_FROM_DATABASE.name) } return true diff --git a/src/main/kotlin/com/hh2/katj/payment/component/PaymentMethodManager.kt b/src/main/kotlin/com/hh2/katj/payment/component/PaymentMethodManager.kt index b831330d..ecca44b0 100644 --- a/src/main/kotlin/com/hh2/katj/payment/component/PaymentMethodManager.kt +++ b/src/main/kotlin/com/hh2/katj/payment/component/PaymentMethodManager.kt @@ -30,8 +30,8 @@ class PaymentMethodManager ( try { paymentMethodRepository.delete(deletePaymentMethod) - } catch (e: Exception) { - throw Exception(ExceptionMessage.INTERNAL_SERVER_ERROR_FROM_DATABASE.name) + } catch (e: RuntimeException) { + throw RuntimeException(ExceptionMessage.INTERNAL_SERVER_ERROR_FROM_DATABASE.name) } return true } @@ -40,8 +40,8 @@ class PaymentMethodManager ( fun deleteAllFavorite(userId: Long): Boolean { try { paymentMethodRepository.deleteAllByUserId(userId) - } catch (e: Exception) { - throw Exception(ExceptionMessage.INTERNAL_SERVER_ERROR_FROM_DATABASE.name) + } catch (e: RuntimeException) { + throw RuntimeException(ExceptionMessage.INTERNAL_SERVER_ERROR_FROM_DATABASE.name) } return true } diff --git a/src/main/kotlin/com/hh2/katj/trip/component/TripManager.kt b/src/main/kotlin/com/hh2/katj/trip/component/TripManager.kt index 3bfbc595..4d85d732 100644 --- a/src/main/kotlin/com/hh2/katj/trip/component/TripManager.kt +++ b/src/main/kotlin/com/hh2/katj/trip/component/TripManager.kt @@ -20,7 +20,7 @@ class TripManager( try { findTrip.updateStatus(TripStatus.END) } catch (e: Exception) { - throw Exception(ExceptionMessage.INTERNAL_SERVER_ERROR_FROM_DATABASE.name) + throw RuntimeException(ExceptionMessage.INTERNAL_SERVER_ERROR_FROM_DATABASE.name) } return findTrip From fd1c9ae531641e804ebc49b494f8afff234e71d1 Mon Sep 17 00:00:00 2001 From: ktony Date: Tue, 24 Oct 2023 20:40:51 +0900 Subject: [PATCH 07/10] =?UTF-8?q?update:=20=EA=B2=B0=EC=A0=9C=20=EC=88=98?= =?UTF-8?q?=EB=8B=A8=20=EB=93=B1=EB=A1=9D=20=EC=99=B8=EB=B6=80=20API=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit profile을 local 사용시에만 true 반환 --- .../payment/service/PaymentMethodValidationApi.kt | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/com/hh2/katj/payment/service/PaymentMethodValidationApi.kt b/src/main/kotlin/com/hh2/katj/payment/service/PaymentMethodValidationApi.kt index d11077e4..54a5f006 100644 --- a/src/main/kotlin/com/hh2/katj/payment/service/PaymentMethodValidationApi.kt +++ b/src/main/kotlin/com/hh2/katj/payment/service/PaymentMethodValidationApi.kt @@ -1,16 +1,21 @@ package com.hh2.katj.payment.service import com.hh2.katj.payment.model.entity.PaymentMethod +import org.springframework.beans.factory.annotation.Value import org.springframework.stereotype.Component @Component class PaymentMethodValidationApi { + + @Value("\${spring.profiles.active}") + private val activeProfile: String? = null + fun bankAccountValidation(paymentMethod: PaymentMethod): Boolean{ /** * 외부 API 사용으로 요청 계좌 정보 유효성 확인 로직 작성 */ paymentMethod.changeValidToTrue() - return true + return activeProfile.isLocal() } fun cardValidation(paymentMethod: PaymentMethod): Boolean { @@ -18,7 +23,11 @@ class PaymentMethodValidationApi { * 외부 API 사용으로 요청 카드 정보 유효성 확인 로직 작성 */ paymentMethod.changeValidToTrue() - return true + return activeProfile.isLocal() } -} \ No newline at end of file +} + +private fun String?.isLocal(): Boolean { + return this.equals("local") +} From 9322dd9ef26be58468ca94e007dcd76d40501664 Mon Sep 17 00:00:00 2001 From: ktony Date: Tue, 24 Oct 2023 22:57:36 +0900 Subject: [PATCH 08/10] =?UTF-8?q?update:=20logger=20=EA=B4=80=EB=A0=A8=201?= =?UTF-8?q?=EC=B0=A8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 정리한 내용 간단하게 적용 되었고, 상세 정보도 수정해야 합니다. 로그들이 실제 파일로 만들어지는 /log/dev/ 폴더는 gitignore에 등록 해두었습니다. --- .gitignore | 1 + src/main/resources/base.xml | 9 +++++++++ src/main/resources/console-appender.xml | 4 +++- src/main/resources/defaults.xml | 7 +++++++ src/main/resources/file-appender.xml | 15 ++++++++------- src/main/resources/logback-spring.xml | 5 +++-- 6 files changed, 31 insertions(+), 10 deletions(-) create mode 100644 src/main/resources/base.xml create mode 100644 src/main/resources/defaults.xml diff --git a/.gitignore b/.gitignore index cc3e6c10..405ee030 100644 --- a/.gitignore +++ b/.gitignore @@ -40,3 +40,4 @@ application-prod.yml ### VS Code ### .vscode/ +/logs/dev/ diff --git a/src/main/resources/base.xml b/src/main/resources/base.xml new file mode 100644 index 00000000..4be18964 --- /dev/null +++ b/src/main/resources/base.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/console-appender.xml b/src/main/resources/console-appender.xml index 1e9e46cc..ae19c5e4 100644 --- a/src/main/resources/console-appender.xml +++ b/src/main/resources/console-appender.xml @@ -1,10 +1,12 @@ + - ${LOG_PATTERN_DEFAULT} + ${CONSOLE_LOG_PATTERN} \ No newline at end of file diff --git a/src/main/resources/defaults.xml b/src/main/resources/defaults.xml new file mode 100644 index 00000000..32f0a9b0 --- /dev/null +++ b/src/main/resources/defaults.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/src/main/resources/file-appender.xml b/src/main/resources/file-appender.xml index 74ad8df0..63a27cf5 100644 --- a/src/main/resources/file-appender.xml +++ b/src/main/resources/file-appender.xml @@ -1,7 +1,8 @@ + @@ -20,6 +21,9 @@ + + ${FILE_LOG_PATTERN} + ERROR NEUTRAL @@ -41,12 +45,12 @@ 10 - - ${LOG_PATTERN_DEFAULT} - + + ${FILE_LOG_PATTERN} + INFO ACCEPT @@ -68,8 +72,5 @@ 10 - - ${LOG_PATTERN_DEFAULT} - \ No newline at end of file diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-spring.xml index 4929e2b2..4e9ef2ec 100644 --- a/src/main/resources/logback-spring.xml +++ b/src/main/resources/logback-spring.xml @@ -1,12 +1,13 @@ - + + + - From eddda6b54d66a7ba9d524f360f1c6e1c5913f4a6 Mon Sep 17 00:00:00 2001 From: ktony Date: Thu, 26 Oct 2023 21:52:30 +0900 Subject: [PATCH 09/10] =?UTF-8?q?update:=20logger=20=EA=B4=80=EB=A0=A8=201?= =?UTF-8?q?=EC=B0=A8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit base.xml 파일과 logback-spring.xml 파일 수정 --- src/main/resources/base.xml | 4 ---- src/main/resources/logback-spring.xml | 10 ++++------ 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/main/resources/base.xml b/src/main/resources/base.xml index 4be18964..adb4780b 100644 --- a/src/main/resources/base.xml +++ b/src/main/resources/base.xml @@ -2,8 +2,4 @@ - - - - \ No newline at end of file diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-spring.xml index 4e9ef2ec..34a848a5 100644 --- a/src/main/resources/logback-spring.xml +++ b/src/main/resources/logback-spring.xml @@ -1,13 +1,14 @@ - - + + + @@ -20,15 +21,12 @@ - - - - + From 61de1dc25dbb2c6fa81772a3d9ef298fbc9e3394 Mon Sep 17 00:00:00 2001 From: ktony Date: Fri, 27 Oct 2023 22:24:20 +0900 Subject: [PATCH 10/10] update: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit default(local) : 콘솔 로그 dev : 콘솔 로그 / log file 저장(콘솔 Info, hibernate) prod : aws에 error 로그 전송 --- src/main/resources/file-appender.xml | 38 +++------------------------ src/main/resources/logback-spring.xml | 10 +++---- 2 files changed, 6 insertions(+), 42 deletions(-) diff --git a/src/main/resources/file-appender.xml b/src/main/resources/file-appender.xml index 63a27cf5..aa274f69 100644 --- a/src/main/resources/file-appender.xml +++ b/src/main/resources/file-appender.xml @@ -19,46 +19,14 @@ - ${FILE_LOG_PATTERN} - - ERROR - NEUTRAL - DENY - - ${LOG_PATH}/${LOG_FILE_NAME}-error.log + ${LOG_PATH}/${LOG_FILE_NAME}.log - ${LOG_PATH}/${LOG_FILE_NAME}-error.%d{yyyy-MM-dd}_%i.log - - - 10MB - - - - 30 - - - 1 - 10 - - - - - - ${FILE_LOG_PATTERN} - - - INFO - ACCEPT - DENY - - ${LOG_PATH}/${LOG_FILE_NAME}-info.log - - ${LOG_PATH}/${LOG_FILE_NAME}-info.%d{yyyy-MM-dd}_%i.log + ${LOG_PATH}/${LOG_FILE_NAME}.%d{yyyy-MM-dd}_%i.log 10MB diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-spring.xml index 34a848a5..98ebd167 100644 --- a/src/main/resources/logback-spring.xml +++ b/src/main/resources/logback-spring.xml @@ -10,23 +10,19 @@ - - + - - + - - + -