From d343161a5df9f5700007ebd077d0b7d4b9743ce1 Mon Sep 17 00:00:00 2001 From: Jisu Hong Date: Fri, 15 May 2026 17:02:04 +0900 Subject: [PATCH 1/3] =?UTF-8?q?:loud=5Fsound:=20=EB=A1=9C=EA=B9=85=20aspec?= =?UTF-8?q?t=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 1 + .../spring2025/common/aop/LoggingAspect.kt | 20 +++++++++++++ .../common/filter/RequestIdFilter.kt | 30 +++++++++++++++++++ .../domain/auth/AuthenticationInterceptor.kt | 4 --- src/main/resources/logback-spring.xml | 30 +++++++++++++++++++ 5 files changed, 81 insertions(+), 4 deletions(-) create mode 100644 src/main/kotlin/com/wafflestudio/spring2025/common/aop/LoggingAspect.kt create mode 100644 src/main/kotlin/com/wafflestudio/spring2025/common/filter/RequestIdFilter.kt create mode 100644 src/main/resources/logback-spring.xml diff --git a/build.gradle.kts b/build.gradle.kts index 5b8d2200..d83a6378 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -40,6 +40,7 @@ repositories { } dependencies { + implementation("org.springframework.boot:spring-boot-starter-aop") implementation("org.springframework.boot:spring-boot-starter-web") implementation("org.springframework.boot:spring-boot-starter-webflux") implementation("org.springframework.boot:spring-boot-starter-data-jdbc") diff --git a/src/main/kotlin/com/wafflestudio/spring2025/common/aop/LoggingAspect.kt b/src/main/kotlin/com/wafflestudio/spring2025/common/aop/LoggingAspect.kt new file mode 100644 index 00000000..a0a4934b --- /dev/null +++ b/src/main/kotlin/com/wafflestudio/spring2025/common/aop/LoggingAspect.kt @@ -0,0 +1,20 @@ +package com.wafflestudio.spring2025.common.aop + +import org.aspectj.lang.annotation.AfterThrowing +import org.aspectj.lang.annotation.Aspect +import org.slf4j.LoggerFactory +import org.springframework.stereotype.Component + +@Aspect +@Component +class LoggingAspect { + private val log = LoggerFactory.getLogger(javaClass) + + @AfterThrowing( + pointcut = "within(com.wafflestudio.spring2025.domain..service..*)", + throwing = "ex", + ) + fun logException(ex: Throwable) { + log.error("Unhandled exception in service", ex) + } +} diff --git a/src/main/kotlin/com/wafflestudio/spring2025/common/filter/RequestIdFilter.kt b/src/main/kotlin/com/wafflestudio/spring2025/common/filter/RequestIdFilter.kt new file mode 100644 index 00000000..1e93fbc5 --- /dev/null +++ b/src/main/kotlin/com/wafflestudio/spring2025/common/filter/RequestIdFilter.kt @@ -0,0 +1,30 @@ +package com.wafflestudio.spring2025.common.filter + +import jakarta.servlet.FilterChain +import jakarta.servlet.http.HttpServletRequest +import jakarta.servlet.http.HttpServletResponse +import org.slf4j.MDC +import org.springframework.core.Ordered +import org.springframework.core.annotation.Order +import org.springframework.stereotype.Component +import org.springframework.web.filter.OncePerRequestFilter +import java.util.UUID + +@Component +@Order(Ordered.HIGHEST_PRECEDENCE) +class RequestIdFilter : OncePerRequestFilter() { + override fun doFilterInternal( + request: HttpServletRequest, + response: HttpServletResponse, + filterChain: FilterChain, + ) { + val requestId = UUID.randomUUID().toString() + MDC.put("requestId", requestId) + response.setHeader("X-Request-Id", requestId) + try { + filterChain.doFilter(request, response) + } finally { + MDC.remove("requestId") + } + } +} diff --git a/src/main/kotlin/com/wafflestudio/spring2025/domain/auth/AuthenticationInterceptor.kt b/src/main/kotlin/com/wafflestudio/spring2025/domain/auth/AuthenticationInterceptor.kt index 460dd584..a0d4a9f2 100644 --- a/src/main/kotlin/com/wafflestudio/spring2025/domain/auth/AuthenticationInterceptor.kt +++ b/src/main/kotlin/com/wafflestudio/spring2025/domain/auth/AuthenticationInterceptor.kt @@ -17,11 +17,7 @@ class AuthenticationInterceptor : HandlerInterceptor { response: HttpServletResponse, handler: Any, ): Boolean { - logger.info("AuthenticationInterceptor pre-handle") - val handlerMethod = handler as? HandlerMethod ?: return true - logger.info(handlerMethod.toString()) - val authRequired = handlerMethod.hasMethodAnnotation(AuthRequired::class.java) || handlerMethod.beanType.isAnnotationPresent(AuthRequired::class.java) diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-spring.xml new file mode 100644 index 00000000..972dfa81 --- /dev/null +++ b/src/main/resources/logback-spring.xml @@ -0,0 +1,30 @@ + + + + + + + ${PATTERN} + + + + + + + 0 + + + + + + + + + + + + + + + From 4e139f981822e5e7b2aafeb61838877c2f1da26e Mon Sep 17 00:00:00 2001 From: Jisu Hong Date: Fri, 15 May 2026 17:02:39 +0900 Subject: [PATCH 2/3] =?UTF-8?q?:loud=5Fsound:=20prod=20=ED=94=84=EB=A1=9C?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20=EB=A1=9C=EA=B9=85=20=EB=A0=88=EB=B2=A8=20?= =?UTF-8?q?=ED=95=84=ED=84=B0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application.yaml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index ee7ef521..9e8e955d 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -132,3 +132,14 @@ oci: vault: secret-ids: ocid1.vaultsecret.oc1.ap-chuncheon-1.amaaaaaat2m5lbqameflpkt7abivvrauqwheybzrkqipf7msv3ol6ikhd3aq region: ap-chuncheon-1 +logging: + level: + org: + springframework: + data: + jdbc: INFO + jdbc: + core: + JdbcTemplate: INFO + namedparam: + NamedParameterJdbcTemplate: INFO From 5e0b9952db5f02e0c9523a927466d09af3d62595 Mon Sep 17 00:00:00 2001 From: Jisu Hong Date: Tue, 19 May 2026 15:59:44 +0900 Subject: [PATCH 3/3] =?UTF-8?q?:loud=5Fsound:=204xx=20=EC=97=90=EB=9F=AC?= =?UTF-8?q?=EB=8A=94=20=EC=BD=9C=EC=8A=A4=ED=83=9D=20=EC=B6=9C=EB=A0=A5=20?= =?UTF-8?q?=EC=95=88=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wafflestudio/spring2025/common/aop/LoggingAspect.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/com/wafflestudio/spring2025/common/aop/LoggingAspect.kt b/src/main/kotlin/com/wafflestudio/spring2025/common/aop/LoggingAspect.kt index a0a4934b..4072b855 100644 --- a/src/main/kotlin/com/wafflestudio/spring2025/common/aop/LoggingAspect.kt +++ b/src/main/kotlin/com/wafflestudio/spring2025/common/aop/LoggingAspect.kt @@ -1,5 +1,6 @@ package com.wafflestudio.spring2025.common.aop +import com.wafflestudio.spring2025.common.exception.DomainException import org.aspectj.lang.annotation.AfterThrowing import org.aspectj.lang.annotation.Aspect import org.slf4j.LoggerFactory @@ -15,6 +16,10 @@ class LoggingAspect { throwing = "ex", ) fun logException(ex: Throwable) { - log.error("Unhandled exception in service", ex) + if (ex is DomainException && ex.httpErrorCode.is4xxClientError) { + log.warn("Expected domain exception: {}", ex.toString()) + } else { + log.error("Unhandled exception in service", ex) + } } }