-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Logging): 로깅에 필요한 Logback MDC 추가
- Loading branch information
Showing
3 changed files
with
116 additions
and
17 deletions.
There are no files selected for viewing
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
40 changes: 40 additions & 0 deletions
40
stempo-auth/src/main/java/com/stempo/filter/MDCFilter.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,40 @@ | ||
package com.stempo.filter; | ||
|
||
import jakarta.servlet.Filter; | ||
import jakarta.servlet.FilterChain; | ||
import jakarta.servlet.ServletException; | ||
import jakarta.servlet.ServletRequest; | ||
import jakarta.servlet.ServletResponse; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import java.io.IOException; | ||
import java.util.UUID; | ||
import org.slf4j.MDC; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class MDCFilter implements Filter { | ||
|
||
@Override | ||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) | ||
throws IOException, ServletException { | ||
|
||
HttpServletRequest httpRequest = (HttpServletRequest) request; | ||
try { | ||
String transactionId = httpRequest.getHeader("X-Transaction-Id"); | ||
if (transactionId == null || transactionId.isEmpty()) { | ||
transactionId = UUID.randomUUID().toString(); | ||
} | ||
MDC.put("transactionId", transactionId); | ||
|
||
String requestId = httpRequest.getHeader("X-Request-Id"); | ||
if (requestId == null || requestId.isEmpty()) { | ||
requestId = UUID.randomUUID().toString(); | ||
} | ||
MDC.put("requestId", requestId); | ||
|
||
chain.doFilter(request, response); | ||
} finally { | ||
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