mirror of https://github.com/usbharu/Hideout.git
feat: mdcを出力するように
This commit is contained in:
parent
e4947ce5a9
commit
0c9faa509b
|
@ -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")
|
||||||
|
}
|
||||||
|
}
|
|
@ -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>
|
||||||
|
|
Loading…
Reference in New Issue