Skip to content

Conversation

@ksg1227
Copy link
Collaborator

@ksg1227 ksg1227 commented May 2, 2025

Related issue 🛠

Work Description 📝

  • MDC 를 활용하여 로그를 추적할 수 있도록 하였습니다.
  • 로그의 형식은 logback-spring.xml 파일을 통해 관리합니다.
  • 이제 각 요청별로 해당 요청의 id ( = request_id), 해당 요청을 보낸 유저의 식별값( = userId) 를 로그에 포함시킵니다.
  • 이 때 로그의 레벨 (error, warn, info) 수준에 따라 서로 다른 파일에 로그가 쌓일 수 있도록 하였습니다.

Screenshot 📸

스크린샷 2025-05-02 오후 1 27 35 스크린샷 2025-05-02 오후 1 28 00

Uncompleted Tasks 😅

To Reviewers 📢

로컬에서 확인하고싶으시면 logs 폴더는 미리 만들어두셔야합니다

@ksg1227 ksg1227 requested review from JJUYAAA and JangIkhwan May 2, 2025 04:28
@ksg1227 ksg1227 linked an issue May 2, 2025 that may be closed by this pull request
1 task
Copy link
Collaborator

@JJUYAAA JJUYAAA left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수고하셨습니다! 궁금한 점이 있어 리뷰 남겼습니다!

finally {
filterChain.doFilter(request, response);
MDC.clear();
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이부분에 MDC.clear()를 넣은 이유가 따로 있을까요? 기능적으로 문제는 없어 보이지만, MDCLoggingFilter에서 이미 finally 블록으로 MDC.clear()를 처리하고 있기 떄문에 JwtFilter의 clear() 호출은 중복되어 불필요하다는 생각이 듭니다!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

주연님 말씀이 맞는 것 같습니다 사실상 중복 코드인 것 같아요. 처음에는 필터단에서의 동작 방식 자체에 대해 약간 부족하게 알고있기도 했고, 혹시나하는 마음에 MDC 를 put 하는 위치마다 모두 clear 를 해주도록 했었는데 그럴 필요가 없을 것 같네용 좋은 지적 감사합니다!
다만 이 브랜치를 베이스 삼아 다음 PR을 열어두어었다보니 잘못하면 커밋 내역이 꼬여버릴 것 같아서 이 부분은 추후에 고쳐둘게요!

Copy link
Collaborator

@JangIkhwan JangIkhwan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수고하셨어요. 로그 파일을 심각도 별로 나누어서 저장하는 점이 인상깊어요! 그리고 궁금한 점이 있는데요. MDCLoggingFilter에서 X-Request-ID 헤더값은 Nginx에서 넘어오는게 맞나요??

@ksg1227
Copy link
Collaborator Author

ksg1227 commented May 5, 2025

수고하셨어요. 로그 파일을 심각도 별로 나누어서 저장하는 점이 인상깊어요! 그리고 궁금한 점이 있는데요. MDCLoggingFilter에서 X-Request-ID 헤더값은 Nginx에서 넘어오는게 맞나요??

네 맞습니다.
EC2 상에 Nginx 설정파일이 존재하는데, 해당 설정 파일 내에 X-Request-ID 헤더 설정을 해두어서 값을 넘겨주는 형태에요.
혹시나 헤더값이 존재하지 않다면 랜덤으로 UUID값을 설정해주는 형태입니당

@ksg1227 ksg1227 merged commit c4f588e into develop May 5, 2025
2 checks passed
@ksg1227 ksg1227 deleted the feat-mdc-logging branch May 5, 2025 15:04
@ksg1227 ksg1227 self-assigned this May 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feat] MDC 로깅 구현

4 participants