Skip to content

chore: AOP 로깅 구현#97

Merged
ohhyungsuh merged 21 commits intodevelopfrom
chore/LCR-344-service-layer-aop-logging-add
Jun 18, 2025
Merged

chore: AOP 로깅 구현#97
ohhyungsuh merged 21 commits intodevelopfrom
chore/LCR-344-service-layer-aop-logging-add

Conversation

@ohhyungsuh
Copy link
Member

@ohhyungsuh ohhyungsuh commented Jun 12, 2025

🌱 관련 이슈


📌 작업 내용 및 특이사항

  • 공통 로깅 구조 도입을 위한 AOP 기반 로깅 시스템을 구성했습니다.
  • Service, Repository, Feign, KafkaProducer, Scheduler, Event 처리 영역에 대해 각각 개별 Aspect를 작성하여, 호출 시점의 로깅을 수행합니다.
  • MDC(Mapped Diagnostic Context)를 활용하여 traceId, memberId를 로그에 자동 포함시킵니다.
    • traceId는 서비스 진입점인 Gateway에서 생성되어 요청 헤더로 전달되며, 각 마이크로서비스에서는 LoggingContextInjectionFilter를 통해 해당 값을 MDC에 주입합니다.
    • 비동기 처리에서도 동일한 traceId, memberId를 유지하기 위해 AsyncConfig 및 MdcTaskDecorator를 구현했습니다. AsyncConfig에서 등록한 Bean 이름을 통해 MemberReservationEventHandler와 같은 클래스에서 해당 TaskDecorator를 적용할 수 있습니다.
    • Scheduler 관련 작업은 Gateway를 거치지 않으므로, Aspect 내부에서 UUID 기반의 traceId를 별도로 생성하여 사용합니다.
  • 서비스 레이어 진입점에서는 메서드 성공 여부와 관계없이 항상 로그가 생성되며, 그 외 영역에서는 CustomException과 Exception을 구분하여 처리합니다.
    • CustomException은 예측 가능한 예외로 판단하여 로그 레벨을 info로 기록합니다.
  • 공통 로깅 유틸리티(LoggingUtil)를 popi-common 모듈에 구현하여, 성능 시간 측정 함수 및 에러 메시지 간략화 함수 등을 제공하도록 구성했습니다.
  • 각 마이크로서비스에 logback-spring.xml 설정 파일을 공통 포맷으로 추가하여, 로그 포맷을 통일했습니다.

📚 참고사항

  • 현재 구현된 Feign 로깅 관련 Aspect는, 향후 gRPC 기반 통신 구조로 전환 시 삭제할 예정입니다.

  • 로그는 logback에 정의된 encoder에 따라 아래와 같은 형태로 출력됩니다.

    • 정상 응답 예시
    {
      "timestamp":"2025-06-15T18:55:33.476",
      "level":"INFO",
      "thread":"http-nio-auto-1-exec-2",
      "logger":"c.l.a.a.ServiceLoggingAspect",
      "traceId":"675c4e79-39d1-4da4-bcaa-56dda928bd81",
      "memberId":"3",
      "message":"[SERVICE] Method: MemberReservationServiceImpl.cancelMemberReservation, Duration: 87ms"
    }
    
    • 에러 응답 예시
    {
      "timestamp":"2025-06-15T18:57:42.404",
      "level":"INFO",
      "thread":"http-nio-auto-1-exec-4",
      "logger":"c.l.a.a.ServiceLoggingAspect",
      "traceId":"744d1158-957d-4281-80d6-1df1165f1cd1",
      "memberId":"3",
      "message":"[CustomException] Method: MemberReservationServiceImpl.cancelMemberReservation, Code: MEMBER_RESERVATION_NOT_FOUND, Message: 회원 예약을 찾을 수 없습니다., Duration: 12ms"
    }
    

@ohhyungsuh ohhyungsuh force-pushed the chore/LCR-344-service-layer-aop-logging-add branch from f086c2e to 57a1017 Compare June 13, 2025 01:06
@ohhyungsuh ohhyungsuh self-assigned this Jun 13, 2025
@ohhyungsuh ohhyungsuh force-pushed the chore/LCR-344-service-layer-aop-logging-add branch 3 times, most recently from b0762bc to 2e181cd Compare June 17, 2025 10:05
Copy link
Member

@ht3064 ht3064 left a comment

Choose a reason for hiding this comment

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

고생하셨습니다! 👍👍

Copy link
Member

@0ssang 0ssang left a comment

Choose a reason for hiding this comment

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

LGTM 👍👍

Copy link
Member

@jeongyeon0208 jeongyeon0208 left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@ohhyungsuh ohhyungsuh force-pushed the chore/LCR-344-service-layer-aop-logging-add branch from 53f5126 to a75eba4 Compare June 18, 2025 13:45
@sonarqubecloud
Copy link

@ohhyungsuh ohhyungsuh merged commit d439a72 into develop Jun 18, 2025
2 checks passed
@ht3064 ht3064 deleted the chore/LCR-344-service-layer-aop-logging-add branch June 18, 2025 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants