Skip to content

feat: 로그 모니터링을 위한 환경 구축#79

Merged
starboxxxx merged 5 commits into
developfrom
feature/#78
Dec 31, 2025
Merged

feat: 로그 모니터링을 위한 환경 구축#79
starboxxxx merged 5 commits into
developfrom
feature/#78

Conversation

@starboxxxx
Copy link
Copy Markdown
Contributor

🍀 이슈 번호


✅ 작업 사항

  • 로그 모니터링을 위한 환경 구축
  • 인증/인가, 도메인 관련 성공/실패 에러 파일로 관리하도록 시스템 구축

⌨ 기타

@starboxxxx starboxxxx self-assigned this Dec 30, 2025
@starboxxxx starboxxxx added the ✨ feat 새로운 기능 추가, 기존 기능을 요구 사항에 맞추어 수정 label Dec 30, 2025
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @starboxxxx, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

이 PR은 포괄적인 로그 모니터링 환경을 구축합니다. 구조화된 로깅을 위해 Logstash를 통합하며, 특히 컨트롤러 상호작용 및 보안 관련 예외에 대한 AOP 기반 로깅을 구현합니다. 이는 오류 및 성공 로깅을 중앙 집중화하고 표준화하여 시스템의 가시성과 문제 해결 능력을 향상시키는 것을 목표로 합니다.

Highlights

  • 로그 모니터링 환경 구축: PR 제목과 본문에 명시된 대로 로그 모니터링을 위한 기반 환경을 구축합니다.
  • 오류 관리 시스템 도입: 인증/인가 및 도메인 관련 성공/실패 오류를 파일로 관리하는 시스템을 구축합니다.
  • Logstash 통합: build.gradle에 logstash-logback-encoder 의존성을 추가하여 구조화된 로깅을 가능하게 합니다.
  • AOP 기반 로깅 구현: AspectUtil, AspectConfig, PointCuts 클래스를 새로 추가하여 컨트롤러 요청 및 보안 필터 예외에 대한 AOP 기반 로깅을 구현합니다.
  • logback-spring.xml 설정 업데이트: LogstashEncoder를 사용하는 ASPECT_JSON appender를 추가하고, com.project.config.log 및 com.project.common.security 패키지의 로그를 해당 appender로 전송하도록 설정합니다.
  • JwtAuthenticationFilter 개선: JwtException 및 AccessDeniedException 발생 시 AspectUtil을 사용하여 요청 정보와 오류 세부 정보를 로깅하도록 필터를 수정합니다.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

이 PR은 AOP와 MDC를 사용하여 컨트롤러 및 인증 필터 수준에서 구조화된 JSON 로그를 생성함으로써 로그 모니터링 환경을 구축합니다. 전반적으로 좋은 접근 방식이지만, 몇 가지 개선점을 제안합니다. 특히, AspectConfig에서 MDC를 정리하는 부분은 동시성 환경에서 발생할 수 있는 로그 오염 문제를 방지하기 위해 finally 블록을 사용하는 것이 중요합니다. 또한 JwtAuthenticationFilter의 예외 처리 로직에서 코드 중복을 줄이고, AspectUtil에서 예외 로깅을 좀 더 상세하게 하여 디버깅을 용이하게 할 수 있습니다.

Comment on lines +24 to +31
public void doReturn(JoinPoint joinPoint, Object result) {
aspectUtil.putCommon(joinPoint);
aspectUtil.putSuccess(result);

log.info("Request Success");

aspectUtil.clear();
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

doReturn 메소드에서 aspectUtil.clear()가 마지막에 호출되고 있습니다. 만약 log.info()와 같은 중간 과정에서 예외가 발생하면 clear()가 호출되지 않아 MDC 정보가 현재 스레드에 남아 다른 요청의 로그를 오염시킬 수 있습니다. try-finally 블록을 사용하여 MDC가 항상 정리되도록 보장하는 것이 안전합니다.

Suggested change
public void doReturn(JoinPoint joinPoint, Object result) {
aspectUtil.putCommon(joinPoint);
aspectUtil.putSuccess(result);
log.info("Request Success");
aspectUtil.clear();
}
public void doReturn(JoinPoint joinPoint, Object result) {
try {
aspectUtil.putCommon(joinPoint);
aspectUtil.putSuccess(result);
log.info("Request Success");
} finally {
aspectUtil.clear();
}
}

Comment on lines +37 to +44
public void doThrowing(JoinPoint joinPoint, Throwable ex) {
aspectUtil.putCommon(joinPoint);
aspectUtil.putError(ex);

log.error("Request Failed");

aspectUtil.clear();
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

doThrowing 메소드 또한 doReturn과 마찬가지로 try-finally 블록을 사용하여 MDC가 항상 정리되도록 해야 합니다. 예외 처리 로직에서 또 다른 예외가 발생할 경우 MDC 정보가 유출(leak)되어 다른 요청의 로그를 오염시킬 수 있습니다.

    public void doThrowing(JoinPoint joinPoint, Throwable ex) {
        try {
            aspectUtil.putCommon(joinPoint);
            aspectUtil.putError(ex);
            log.error("Request Failed");
        } finally {
            aspectUtil.clear();
        }
    }

Comment on lines +56 to +58
HttpServletRequest request,
HttpServletResponse response,
FilterChain filterChain
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

상위 클래스인 OncePerRequestFilterdoFilterInternal 메소드는 파라미터에 org.springframework.lang.NonNull 애노테이션을 사용하고 있습니다. 코드의 명확성과 일관성을 위해, 그리고 Spring 프레임워크와의 호환성을 위해 @NonNull 애노테이션을 추가하는 것을 권장합니다. @NotNull이 제거되었는데, org.springframework.lang.NonNull을 import하여 @NonNull로 대체하는 것이 좋습니다.

Suggested change
HttpServletRequest request,
HttpServletResponse response,
FilterChain filterChain
@NonNull HttpServletRequest request,
@NonNull HttpServletResponse response,
@NonNull FilterChain filterChain

Comment on lines +69 to 86
} catch (JwtException ex) {
aspectUtil.putCommonFromRequest(request);
aspectUtil.putError(ex);

log.error("Authentication Error");

aspectUtil.clear();
throw ex;

} catch (AccessDeniedException ex) {
aspectUtil.putCommonFromRequest(request);
aspectUtil.putError(ex);

log.error("Access Denied Error");

aspectUtil.clear();
accessDeniedHandler.handle(request, response, ex);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

JwtExceptionAccessDeniedException을 처리하는 catch 블록에 로깅 관련 코드가 중복되고 있습니다. 코드 가독성과 유지보수성을 높이기 위해 이 로직을 별도의 private 헬퍼 메소드로 추출하는 것을 고려해 보세요.

예시:

private void logAndClearMdc(HttpServletRequest request, Throwable ex, String errorMessage) {
    aspectUtil.putCommonFromRequest(request);
    aspectUtil.putError(ex);
    log.error(errorMessage);
    aspectUtil.clear();
}

// ...

} catch (JwtException ex) {
    logAndClearMdc(request, ex, "Authentication Error");
    throw ex;
} catch (AccessDeniedException ex) {
    logAndClearMdc(request, ex, "Access Denied Error");
    accessDeniedHandler.handle(request, response, ex);
}

}
else {
MDC.put("errorCode", "UNEXPECTED");
MDC.put("errorMessage", shorten(ex.getMessage()));
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

예상치 못한 예외가 발생했을 때, 예외 메시지만 로깅하면 원인 파악이 어려울 수 있습니다. 예외 클래스 이름을 함께 로깅하여 디버깅 시 더 많은 컨텍스트를 제공하는 것이 좋습니다.

Suggested change
MDC.put("errorMessage", shorten(ex.getMessage()));
MDC.put("errorMessage", ex.getClass().getName() + ": " + shorten(ex.getMessage()));

@starboxxxx starboxxxx merged commit 54528a7 into develop Dec 31, 2025
1 check failed
@starboxxxx starboxxxx deleted the feature/#78 branch December 31, 2025 01:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

✨ feat 새로운 기능 추가, 기존 기능을 요구 사항에 맞추어 수정

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant