Skip to content

Commit 30dee19

Browse files
Darren4641darren
andauthored
chore/#122 -> staging merge commit
Co-authored-by: darren <darren@darrenui-MacBookPro.local>
1 parent bcedba1 commit 30dee19

File tree

6 files changed

+67
-5
lines changed

6 files changed

+67
-5
lines changed

src/main/kotlin/com/yapp2app/auth/infra/oauth/OidcTokenValidator.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,10 @@ class OidcTokenValidator(
4242
// 1차 시도: 캐시된 공개키로 토큰 검증
4343
validateTokenWithPublicKeys(idToken, oidcAdapter, oauthHelperAdapter, platform)
4444
} catch (e: BusinessException) {
45-
log.info("Kakao OIDC token expired. 갱신 로직")
4645
// 캐시 무효화 후 재시도
4746
authRedisCacheAdapter.clearPublicKeys(AuthCacheKeys.KAKAO_OIDC_KEY)
4847
validateTokenWithPublicKeys(idToken, oidcAdapter, oauthHelperAdapter, platform)
4948
} catch (e: Exception) {
50-
e.printStackTrace() // TODO 인증 실패 예외 로그 모니터링용
5149
throw e
5250
}
5351
}

src/main/kotlin/com/yapp2app/auth/infra/oauth/oidc/KakaoOidc.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ class KakaoOidc(
4141
val cached = authRedisCacheAdapter.getPublicKeys(AuthCacheKeys.KAKAO_OIDC_KEY)
4242

4343
if (cached != null) {
44-
log.info("Found cached OIDC key") // TODO 임시 코드
4544
return cached
4645
}
4746

src/main/kotlin/com/yapp2app/common/exception/handler/ExceptionHandler.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class ExceptionHandler {
3030

3131
@ExceptionHandler(BusinessException::class)
3232
fun businessExceptionHandler(ex: BusinessException): ResponseEntity<ExceptionMsg> {
33-
log.error("{} message = {}", ex.resultCode.code, ex.resultCode.message)
33+
log.error("[BUSINESS_ERROR] code={} | message={}", ex.resultCode.code, ex.resultCode.message)
3434

3535
if (ex.resultCode == ResultCode.INVALID_TOKEN_ERROR) {
3636
return ResponseEntity(
@@ -55,7 +55,7 @@ class ExceptionHandler {
5555

5656
@ExceptionHandler(Exception::class)
5757
fun exceptionHandler(ex: Exception): ResponseEntity<ExceptionMsg> {
58-
log.error("No Handler ex message = {}", ex)
58+
log.error("[SYSTEM_ERROR] unhandled exception", ex)
5959

6060
val temp = ResponseEntity(
6161
ExceptionMsg(
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.yapp2app.common.filter
2+
3+
import jakarta.servlet.FilterChain
4+
import jakarta.servlet.http.HttpServletRequest
5+
import jakarta.servlet.http.HttpServletResponse
6+
import org.slf4j.LoggerFactory
7+
import org.slf4j.MDC
8+
import org.springframework.web.filter.OncePerRequestFilter
9+
10+
/**
11+
* API 요청의 수명주기(응답 시간, 상태 코드)를 로깅하는 필터.
12+
* RequestMdcFilter 이후에 실행되어 MDC 컨텍스트(requestId, userId)를 활용한다.
13+
*
14+
* JSON 로그: message는 간결하게, 상세 정보는 MDC 필드(durationMs, responseStatus, logCategory)로 분리.
15+
* 콘솔 로그: [API_REQUEST] POST /api/auth/kakao/login | status=200 | duration=342ms
16+
*/
17+
class RequestLoggingFilter : OncePerRequestFilter() {
18+
19+
private val log = LoggerFactory.getLogger(javaClass)
20+
21+
override fun doFilterInternal(
22+
request: HttpServletRequest,
23+
response: HttpServletResponse,
24+
filterChain: FilterChain,
25+
) {
26+
val startTime = System.currentTimeMillis()
27+
28+
try {
29+
filterChain.doFilter(request, response)
30+
} finally {
31+
val duration = System.currentTimeMillis() - startTime
32+
val status = response.status
33+
34+
MDC.put("logCategory", "API_REQUEST")
35+
MDC.put("durationMs", duration.toString())
36+
MDC.put("responseStatus", status.toString())
37+
38+
log.info("[API_REQUEST]")
39+
40+
MDC.remove("logCategory")
41+
MDC.remove("durationMs")
42+
MDC.remove("responseStatus")
43+
}
44+
}
45+
46+
override fun shouldNotFilter(request: HttpServletRequest): Boolean {
47+
val uri = request.requestURI
48+
return uri.startsWith("/actuator") ||
49+
uri.startsWith("/swagger-ui") ||
50+
uri.startsWith("/v3/api-docs") ||
51+
uri.startsWith("/file")
52+
}
53+
}

src/main/kotlin/com/yapp2app/common/filter/ServletFilterConfig.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ class ServletFilterConfig {
1919

2020
@Bean
2121
fun requestMdcFilterRegistration(filter: RequestMdcFilter): FilterRegistrationBean<RequestMdcFilter> =
22+
FilterRegistrationBean(filter).apply {
23+
order = SecurityProperties.DEFAULT_FILTER_ORDER - 2
24+
}
25+
26+
@Bean
27+
fun requestLoggingFilter(): RequestLoggingFilter = RequestLoggingFilter()
28+
29+
@Bean
30+
fun requestLoggingFilterRegistration(filter: RequestLoggingFilter): FilterRegistrationBean<RequestLoggingFilter> =
2231
FilterRegistrationBean(filter).apply {
2332
order = SecurityProperties.DEFAULT_FILTER_ORDER - 1
2433
}

src/main/resources/logback-spring.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
<includeMdcKeyName>requestMethod</includeMdcKeyName>
2828
<includeMdcKeyName>requestUri</includeMdcKeyName>
2929
<includeMdcKeyName>clientIp</includeMdcKeyName>
30+
<includeMdcKeyName>logCategory</includeMdcKeyName>
31+
<includeMdcKeyName>durationMs</includeMdcKeyName>
32+
<includeMdcKeyName>responseStatus</includeMdcKeyName>
3033

3134
<!-- 기본 필드명 커스터마이징 -->
3235
<fieldNames>

0 commit comments

Comments
 (0)