-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BBB-153] ✨Feat: 쓰레드 별로 요청을 구분하기 위해 MDC에 uuid 추가 & 로그 형식 변경
- Loading branch information
1 parent
7368e5b
commit b2cd255
Showing
2 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
...api/src/main/java/com/bombombom/devs/external/global/logging/filter/MDCLoggingFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.bombombom.devs.external.global.logging.filter; | ||
|
||
import jakarta.servlet.Filter; | ||
import jakarta.servlet.FilterChain; | ||
import jakarta.servlet.ServletException; | ||
import jakarta.servlet.ServletRequest; | ||
import jakarta.servlet.ServletResponse; | ||
import java.io.IOException; | ||
import java.util.UUID; | ||
import org.slf4j.MDC; | ||
import org.springframework.core.Ordered; | ||
import org.springframework.core.annotation.Order; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@Order(Ordered.HIGHEST_PRECEDENCE) | ||
class MDCLoggingFilter implements Filter { | ||
|
||
@Override | ||
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, | ||
FilterChain filterChain) throws IOException, ServletException { | ||
final UUID uuid = UUID.randomUUID(); | ||
MDC.put("requestId", uuid.toString()); | ||
filterChain.doFilter(servletRequest, servletResponse); | ||
MDC.clear(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<configuration> | ||
<timestamp key="BY_DATE" datePattern="yyyy-MM-dd"/> | ||
<property name="LOG_PATTERN" | ||
value="[%d{yyyy-MM-dd HH:mm:ss}:%-4relative] [%X{requestId:-startup}] %green([%thread]) %highlight(%-5level) %boldWhite([%C.%M:%yellow(%L)]) - %msg%n"/> | ||
<springProfile name="!prod"> | ||
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"> | ||
<encoder> | ||
<pattern>${LOG_PATTERN}</pattern> | ||
</encoder> | ||
</appender> | ||
<root level="INFO"> | ||
<appender-ref ref="CONSOLE"/> | ||
</root> | ||
</springProfile> | ||
</configuration> |