-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feat] #310 - log4j2를 이용한 AOP 로깅방식 도입 완료 #311
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- 스프링에서 JPA와 Redis 레포지토리 간 충돌 문제 해결을 위한 설정 추가
- 컨트롤러의 요청 정보를 로깅하는 @before 추가 - 컨트롤러의 정상 응답을 로깅하는 @AfterReturning 추가 - 컨트롤러에서 예외 발생 시 로깅하는 @AfterThrowing 추가 - HTTP 요청의 파라미터를 JSON 형태로 변환하여 로깅 - Order(2) 적용하여 트랜잭션 관리(AOP)보다 후순위로 실행되도록 설정
- 서비스 레이어에서 트랜잭션의 시작, 커밋, 롤백, 리소스 릴리즈를 로깅하도록 TxAspect 구현 - @transactional 애너테이션 정보를 읽어 트랜잭션 속성(readOnly, propagation, isolation) 로깅 추가 - 트랜잭션 실행 시간을 측정하여 성능 모니터링 가능하도록 개선 - 트랜잭션이 적용되는 메서드를 Pointcut으로 지정하여 관리
- 컨트롤러, 서비스, 애플리케이션 로직을 대상으로 하는 AOP 포인트컷 정의 - `allController()`: 모든 컨트롤러 메서드를 대상으로 지정 - `allService()`: 서비스, UseCase, Facade 계층의 메서드를 대상으로 지정 - `allApplicationLogic()`: 글로벌 설정을 제외한 모든 애플리케이션 로직을 대상으로 지정 - AOP 기반의 로깅 및 트랜잭션 관리를 위한 공통 포인트컷으로 활용 가능
1 task
- prod 환경에서는 서비스 계층의 실행속도만 로깅 - local, dev 환경에서는 모든 계층의 실행속도를 로깅
hyerinhwang-sailin
approved these changes
Feb 22, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
log4j2 도입 넘 좋네요!!
동기 방식 모니터링 후 비동기 일부 도입하는 방식도 좋습니다!
다만 로그가 한 요청에도 꽤 길어서 prod에서는 좀 더 간소화하는 방향으로 가면 좋을 것 같아요~~
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related issue 🛠
Work Description ✏️
log4j2 설명
결론
log4j2-spring.xml
비동기 로깅의 단점
1. 로그 유실 가능성 (Lost Logs)
2. 로깅 실패 감지 어려움 (Error Handling Challenge)
결론
AOP 도입
Pointcuts.java
allController()
: com.beat 패키지 아래의 모든 Controller 클래스의 메서드에 AOP 적용allService()
: Service, UseCase, Facade 클래스를 포함하는 비즈니스 로직 계층에 AOP 적용allApplicationLogic()
: com.beat.global 패키지를 제외한 모든 클래스의 메서드에 AOP 적용 (이 부분은 추후 변동성 있음)ExecutionTimeLoggerAspect.java
ControllerLoggingAspect.java
ServiceLoggingAspect.java
TxAspect.java
왜 이렇게 했는가?
Aspect Order의 순서
Trouble Shooting ⚽️
Related ScreenShot 📷
기존 logging 모듈 삭제
AS-IS
TO-BE
AOP 적용 시 로깅
Uncompleted Tasks 😅
To Reviewers 📢
log4j2 참고 블로그
AOP 참고 블로그