feat: mdcを出力するように

This commit is contained in:
usbharu 2024-08-24 12:57:33 +09:00
parent e4947ce5a9
commit 0c9faa509b
Signed by: usbharu
GPG Key ID: 6556747BF94EEBC8
2 changed files with 34 additions and 1 deletions

View File

@ -0,0 +1,33 @@
package dev.usbharu.hideout.core.infrastructure.springframework
import jakarta.servlet.http.HttpServletRequest
import jakarta.servlet.http.HttpServletResponse
import org.slf4j.MDC
import org.springframework.stereotype.Component
import org.springframework.web.servlet.AsyncHandlerInterceptor
import java.util.*
@Component
class MdcInterceptor() : AsyncHandlerInterceptor {
override fun preHandle(request: HttpServletRequest, response: HttpServletResponse, handler: Any): Boolean {
MDC.put("request", UUID.randomUUID().toString())
return true
}
override fun afterConcurrentHandlingStarted(
request: HttpServletRequest,
response: HttpServletResponse,
handler: Any
) {
MDC.remove("request")
}
override fun afterCompletion(
request: HttpServletRequest,
response: HttpServletResponse,
handler: Any,
ex: Exception?
) {
MDC.remove("request")
}
}

View File

@ -2,7 +2,7 @@
<Configuration status="WARN"> <Configuration status="WARN">
<Appenders> <Appenders>
<Console name="Console" target="SYSTEM_OUT"> <Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/> <PatternLayout pattern="%d{HH:mm:ss.SSS} [%.15t] %highlight{%-5level} %x %logger{36} - %msg%n"/>
</Console> </Console>
</Appenders> </Appenders>
<Loggers> <Loggers>