songining
article thumbnail
Spring WebFlux ๊ธฐ๋ฐ˜ MDC ์ ์šฉํ•˜๊ธฐ (+์ฝ”๋ฃจํ‹ด)
BACKEND/Spring 2023. 8. 12. 22:20

MDC ๋ž€? MDC ๋Š” Mapped Diagnostic Context ์˜ ์•ฝ์ž๋กœ key์™€ value๋ฅผ ์ €์žฅํ•˜๋Š” Map ํ˜•์‹์œผ๋กœ slf4j, logback, log4j ๋“ฑ ๋กœ๊น… ํ”„๋ ˆ์ž„์›Œํฌ์—์„œ ํ•„์š”ํ•œ ์ •๋ณด๋ฅผ ์ €์žฅํ•˜๊ณ  ์‹ถ์„ ๋•Œ ์‚ฌ์šฉํ•œ๋‹ค. ThreadLocal ์„ ๊ธฐ๋ฐ˜์œผ๋กœ ์ปจํ…์ŠคํŠธ ์ •๋ณด๋ฅผ ์ €์žฅํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๋ฉ€ํ‹ฐ ์“ฐ๋ ˆ๋“œ ํ™˜๊ฒฝ์—์„œ ์œ ์šฉํ•˜๊ฒŒ ์‚ฌ์šฉ์ด ๊ฐ€๋Šฅํ•˜๋‹ค. (๋ฉ€ํ‹ฐ ์“ฐ๋ ˆ๋“œ ํ™˜๊ฒฝ์—์„œ๋Š” ๋กœ๊ทธ ๋ฉ”์‹œ์ง€์— ๊ฐ ์“ฐ๋ ˆ๋“œ์— ๋Œ€ํ•œ ๋กœ๊ทธ๊ฐ€ ์„ž์ด๊ธฐ ๋•Œ๋ฌธ) ์š”์ฒญ์ด ์–ด๋–ค ์‚ฌ์šฉ์ž๋กœ๋ถ€ํ„ฐ ๋“ค์–ด์˜จ ๊ฒƒ์ธ์ง€ ์ €์žฅํ•˜๊ฑฐ๋‚˜ ์š”์ฒญ๋ณ„๋กœ ์‹๋ณ„์ž๋ฅผ ๋งŒ๋“ค์–ด ํŠน์ • ์š”์ฒญ์— ๋Œ€ํ•œ ๋กœ๊ทธ๋งŒ ์ถ”์ ํ•  ์ˆ˜ ์žˆ๋‹ค. ์ฐธ๊ณ : ๋กœ๊ทธ์‹œ์Šคํ…œ #4-MDC๋ฅผ ์ด์šฉํ•˜์—ฌ ์“ฐ๋ ˆ๋“œ๋ณ„๋กœ ๋กœ๊ทธ ๋ถ„๋ฅ˜ํ•˜๊ธฐ MDC ์ ์šฉํ•˜๊ธฐ Spring Framework๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๋‹ค๋ฉด AOP๋ฅผ ์ด์šฉํ•ด ์‰ฝ๊ฒŒ ์ ์šฉ์ด ๊ฐ€๋Šฅํ•˜๋‹ค...