ํฐ์คํ ๋ฆฌ ๋ทฐ
Spring MDC๋ฅผ ์ฌ์ฉํด ์๋ณ๊ฐ๋ฅํ ๋ก๊ทธ ๋จ๊ธฐ๊ธฐ
์ฃผ๋ฌ 2023. 7. 17. 16:16Spring MDC๋ฅผ ์ฌ์ฉํด ์๋ณ๊ฐ๋ฅํ ๋ก๊ทธ ๋จ๊ธฐ๊ธฐ
์ด์์ ํ๋ค ๋ณด๋ฉด ๋ก๊ทธ๋ฅผ ์ถ์ ํด์ ํ์ธํด์ผ ํ ๋๊ฐ ์๊ธฐ๋๋ฐ ์ฌ๋ฌ ์์ฒญ์ด ํ๊บผ๋ฒ์ ๋ค์ด์ค๋ฉด ๋ก๊ทธ๊ฐ ์์ ์์ด ์์ฌ ํ์ธํ๊ธฐ ์ด๋ ค์ธ๋๊ฐ ์์ต๋๋ค. ์ด๋ด๋ ์์ฒญ๋น ์ ๋ํฌํ ๊ฐ์ ์ฃผ์ด ๋ก๊ทธ์ ํจ๊ป ์ถ๋ ฅํจ์ผ๋ก์จ ์ถ์ ํ ์ ์์ต๋๋ค.
MDC (Mapped Diagnostic Context)
- ๋ฉํฐ ์ฐ๋ ๋ํ๊ฒฝ์์ ํ์ฌ ์คํ์ค์ธ ์ฐ๋ ๋์ ๋ฉํ ์ ๋ณด๋ฅผ ๋ฃ๊ณ ๊ด๋ฆฌํ๋ ๊ณต๊ฐ์ ๋๋ค. ๋ด๋ถ์ ์ผ๋ก Map์ผ๋ก ๊ด๋ฆฌํ๊ณ ์๊ณ ThreadLocal์ ํค ๊ฐ์ ์ ์ฅํ์ฌ Thread๊ฐ ์กด์ฌํ๋ ๋์ ๊ณ์ ์ฌ์ฉํ ์ ์๊ฒ ํฉ๋๋ค.
MDC ํํฐ์ ๊ตฌํํ๊ธฐ
@Component
@Order(Ordered.HIGHEST_PRECEDENCE)
public class MDCLoggingFilter implements Filter {
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
MDC.put("uuid", UUID.randomUUID().toString().replaceAll("-", ""));
chain.doFilter(request, response);
MDC.clear();
}
}
MDC๋ฅผ ๋ฃ์ด์ค๋งํ๊ณณ์ ํํฐ๋ ์ธํฐ์ ํฐ๋ฑ์ด ์๋๋ฐ ๊ฐ์ฅ ์๋จ์ธ ํํฐ์ ์ ์ฉํ๋๊ฒ์ด ์ข๊ณ ํํฐ์ค์๋ ๊ฐ์ฅ ์๋จ์ ๋จผ์ ๋ฑ๋กํด์ค๋ค.
Spring MVC๋ ์ฐ๋ ๋๋ฅผ ๋ง๋ค์ด ๋์๋ค๊ฐ ์์ฒญ์ด ๋ค์ด์ค๋ฉด ๋ง๋ค์ด๋ ์ฐ๋ ๋๋ฅผ ๊ฐ์ ธ์์ ์ฌ์ฉ ์ฒ๋ฆฌํ ๋ฐ๋ฉํ๋ค. ๋ฐ๋ผ์ ์ฐ๋ ๋๋ฅผ ์ฌ์ฌ์ฉํ๊ธฐ ๋๋ฌธ์ ์ด์ ๋ฐ์ดํฐ๊ฐ ๋จ์ ์์์ ์์ผ๋ฏ๋ก MDC.clear์ด ํด์ค๋๋ค.
logback ํจํด
// Logback
%X{<ํค๊ฐ>:-<Default>}]
[%X{uuid:-startup}] %d{yyyy-MM-dd HH:mm:ss.SSS} %5p [%t] %-40.40logger{39} [%4L] : %m%n
๋จ์ผ์๋ฒ๋ด์์ ์ฌ์ฉ์ ํ๊ณ ๋ถ์ฐํ๊ฒฝ์ผ ๊ฒฝ์ฐ spring-cloud-sleuth๋ฅผ ์ฐธ๊ณ ํ์ธ์
์ฐธ๊ณ
'๐บ Develop > ๐ด Spring' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
Springboot console ๋ก๊ทธ๋ฅผ ์๋ฆ๋ต๊ฒ ๊พธ๋ฉฐ๋ณด์ (0) | 2024.05.11 |
---|---|
AOP๋ฅผ ์ฌ์ฉํ์ฌ custom Annotation์ Log๋ง ์ถ๋ ฅํ๊ธฐ (0) | 2023.07.17 |
Springboot graceful shutdown ์ ์ฉํ๊ธฐ (0) | 2023.07.14 |
Springboot ์ฝ์ ๋ฐฐ๋ ๋ณ๊ฒฝ (0) | 2023.03.05 |
[Springboot] Jasypt ์ค์น ๋ฐ ์ค์ (0) | 2022.10.11 |
- Total
- Today
- Yesterday
- pip ํจํค์ง
- ๋งฅ๋ถ gcp
- pip requirements ์ค์น
- ๋งฅ๋ถgcp
- macos gcp
- ๋งฅ ์ฑ ์ถ์ฒ
- pip ํจํค์ง ๋ชฉ๋ก
- pip requirements ์์ฑ
- pip requirements
- ๋งฅ๋ฆฐ์ด ์ฑ ์ถ์ฒ
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 | 31 |