기존 어드민 API 요청 로깅은 AdminLoggingInterceptor와 AdminApiLoggingAspect 두 곳에 분산되어 있었음.
log.info(...) 직접 반복기존 구조를 유지하면서도 로깅 책임을 완전히 분리하기 위해 다음과 같은 구조를 설계:
RequestLogContext에 담아 ThreadLocal에 저장LoggingUtils에 위임RequestLogContext 객체 생성: 요청 시간, URI, 메서드, 사용자 ID 등 포함RequestLogContextHolder: ThreadLocal 기반으로 요청별 Context 보관LoggingUtils: ObjectMapper를 이용해 args/response를 JSON으로 출력AdminApiLoggingAspect → LoggingUtils 호출만 하도록 리팩토링AdminLoggingInterceptor → Context만 set/clear| 항목 | 개선 전 | 개선 후 |
|---|---|---|
| 로그 출력 위치 | 여러 클래스 직접 log.info | LoggingUtils 단일 진입점 |
| 중복 포맷 로직 | O (Interceptor + AOP 중복) | X |
| 테스트 가능성 | 낮음 | LoggingUtils 단위 테스트 가능 |
| 확장성 (DB 저장 등) | 어려움 | LoggingUtils 확장 가능 |
🟡 [REQUEST] [2025-04-19T16:29:58.572894] DELETE /admin/comments/2, userId=1, role=ADMIN, body=[2]
🟢 [RESPONSE] [2025-04-19T16:29:58.572894] DELETE /admin/comments/2, userId=1, result=null