Skip to content

로그 카테고리 분리와 MDC 기반 요청 상관관계 구축#250

Open
Goder-0 wants to merge 1 commit into
mainfrom
feature/#242-log-categories-mdc
Open

로그 카테고리 분리와 MDC 기반 요청 상관관계 구축#250
Goder-0 wants to merge 1 commit into
mainfrom
feature/#242-log-categories-mdc

Conversation

@Goder-0

@Goder-0 Goder-0 commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

관련 이슈

PR 설명

Overview

  • access/app/audit 로그를 역할별로 나눌 수 있는 기반을 추가했습니다.
  • requestId/traceId/memberId/linkId/chatId MDC를 공통 컨텍스트로 넣고, 비동기 실행 흐름까지 전파되도록 정리했습니다.

Changes

  • RequestLoggingFilter를 access 로그 중심으로 변경하고 requestId/traceId를 생성하도록 수정
  • logback-spring.xml에 MDC 패턴 및 access.log, audit.log appender 추가
  • LogContext, MdcTaskDecorator, AccessLogger, AuditLogger, RequestContextInterceptor 추가
  • @Async, MVC async executor에 MDC task decorator 적용
  • link sync event, summary queue/worker, chat async 응답 생성 흐름에 MDC 복원/전파 적용
  • OAuth2 로그인 성공/실패, 인증 실패, websocket 인증 실패를 audit 로그로 남기도록 추가
  • 링크 API의 /{id} 경로에서도 linkId MDC가 채워지도록 보정
  • local profile에서는 access/audit 파일 로그가 생기지 않도록 profile 범위 정리

@Goder-0 Goder-0 requested a review from ckdals4600 June 24, 2026 14:11
@Goder-0 Goder-0 linked an issue Jun 24, 2026 that may be closed by this pull request
@Goder-0 Goder-0 force-pushed the feature/#242-log-categories-mdc branch from 9a6f092 to 3bfc02e Compare June 25, 2026 15:31
@Goder-0 Goder-0 force-pushed the feature/#242-log-categories-mdc branch from 3bfc02e to 9d81e30 Compare June 25, 2026 15:42
@github-actions

Copy link
Copy Markdown

📊 코드 커버리지 리포트

Overall Project 93.64% -0.97% 🍏
Files changed 93.73% 🍏

File Coverage
LinkEventListener.java 100% 🍏
LinkSyncEvent.java 100% 🍏
LinkCreatedEvent.java 100% 🍏
LinkSyncEventListener.java 100% 🍏
AccessLogger.java 100% 🍏
RequestContextInterceptor.java 100% 🍏
MdcTaskDecorator.java 100% 🍏
RagChatService.java 100% 🍏
SummaryTask.java 100% 🍏
SummaryWorker.java 100% 🍏
SummaryQueue.java 100% 🍏
LogContext.java 98.55% -1.45% 🍏
LinkFacade.java 96.35% 🍏
RequestLoggingFilter.java 72.33% -27.67% 🍏
CustomAuthenticationEntryPoint.java 67.11% 🍏
AuditLogger.java 60% -40% 🍏

@ckdals4600

ckdals4600 commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

memberId를 MDC에 세팅하는 로직이 두 곳에 중복되어 있는 것 같습니다.

RequestContextInterceptor.preHandle()CustomMemberDetail에서 memberId 추출 후 MDC 세팅
RequestLoggingFilter.populateAuthenticatedMemberContext() — 동일하게 추출 후 세팅

두 곳이 같은 일을 하는데, 타이밍 때문에 동작도 미묘하게 달라지는 것 같습니다.
필터의 populateAuthenticatedMemberContext()filterChain.doFilter() 이후에 호출되어서, 정작 요청 처리 중에 찍히는 application 로그에는 이 시점의 memberId가 반영되지 않습니다
인터셉터가 preHandle에서 넣어주기 때문에 결과적으로는 찍히지만, 필터 쪽 세팅은 access 로그에만 영향을 줍니다.

인증 정보는 컨트롤러 진입 전인 인터셉터에서 넣는 것이 자연스러우니, 필터의 populateAuthenticatedMemberContext()는 제거하고 RequestContextInterceptor로 일원화하는 것을 제안합니다. 한 곳에서만 관리하면 책임도 명확해질 것 같습니다.
다만 access 로그에도 memberId가 필요하다면, 인터셉터가 이미 MDC에 넣은 값을 필터에서 그대로 참조하면 될 것 같습니다.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

#245 의 작업과 겹치는 부분이 있는 것 같아 의견 남깁니다!
먼저 logAccess 에서 #245 에 있던 아래와 같은 내용이 빠져있는 걸로 확인되며

  • 쿼리스트링 마스킹 (?code=, ?state= 등 민감 파라미터 값 마스킹)
  • 헤더 마스킹 (authorization, cookie 등)
  • 요청/응답 바디 마스킹 (email, password, token 및 JWT 패턴)
  • skip 경로 (/actuator, /health-check 등)
  • clientIp(X-Forwarded-For) — 이슈의 access 필드 정의(clientIp)에도 포함된 항목

반대로 #245 에는 없는 requestId/traceId MDC 세팅과 ACCESS 전용 로거가 새로 들어와 있어서, 두 작업은 충돌이라기보다 상호보완에 가깝다고 생각됩니다.
어느 한쪽만 머지되면 다른 쪽이 덮어써질 것 같아서, 머지 순서와 통합 방식을 먼저 맞추면 좋을 것 같습니다.

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.

로그 카테고리 분리와 MDC 기반 요청 상관관계 구축

2 participants