Skip to content

예외 로깅 레벨 4xx/5xx 분리#246

Open
ckdals4600 wants to merge 1 commit into
mainfrom
feature/#243-separate-exception
Open

예외 로깅 레벨 4xx/5xx 분리#246
ckdals4600 wants to merge 1 commit into
mainfrom
feature/#243-separate-exception

Conversation

@ckdals4600

@ckdals4600 ckdals4600 commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

관련 이슈

PR 설명

배경

  • 모든 핸들러가 log.error(ex.getMessage(), ex)로 동일하게 로깅하여,
    클라이언트 잘못인 4xx(검증 실패, 405, 404 등)까지 ERROR + 풀스택으로 기록됨.
  • 운영 로그에서 Request method 'POST' is not supported, 채팅을 찾을 수 없습니다 등이 ERROR 로 다수 확인됨.
  • 이 상태로 ERROR 알림을 도입하면 클라이언트 실수 때문에 계속 울려 알림이 무의미해짐.

적용된 로깅 원칙

  • 4xx (클라이언트 잘못): WARN, 스택 트레이스 없이 메시지만. 서버 문제가 아니므로 ERROR 금지.
  • 5xx (서버 잘못): ERROR, 예외 객체를 넘겨 전체 스택 트레이스를 남김.
  • 봇 스캔성 404 등 고빈도 노이즈: DEBUG.
  • 민감 데이터가 들어가는 예외라면 메시지를 그대로 찍지 말고 필요한 필드만 추려 남길 것.

변경 사항

  • 검증/바인딩/HTTP 메서드 예외(확정 4xx) → WARN, 스택 트레이스 없이 핵심 필드만 기록
  • BusinessExceptionErrorCode.getStatus()로 분기: 5xx만 ERROR + 스택, 4xx는 WARN
  • catch-all Exception(예상 못 한 5xx) → ERROR + 풀스택 유지, 예외 객체를 인자로 전달
  • 메시지에 요청 본문/PII가 섞일 수 있는 예외는 고정 문구만 기록

@ckdals4600 ckdals4600 self-assigned this Jun 21, 2026
@ckdals4600 ckdals4600 requested review from Goder-0 and minibr June 21, 2026 07:53
@github-actions

github-actions Bot commented Jun 21, 2026

Copy link
Copy Markdown

📊 코드 커버리지 리포트

Overall Project 94.36% -0.78% 🍏
Files changed 36.51% 🍏

File Coverage
GlobalExceptionHandler.java 39.6% -39.6% 🍏

@ckdals4600 ckdals4600 force-pushed the feature/#243-separate-exception branch from fd18b29 to 2c0b406 Compare June 24, 2026 13:42
@ckdals4600 ckdals4600 requested a review from Goder-0 June 28, 2026 04:28
@ExceptionHandler(MethodArgumentNotValidException.class)
public ResponseEntity<BaseResponse<String>> handleMethodArgumentNotValid(MethodArgumentNotValidException ex) {
log.error(ex.getMessage(), ex);
log.warn("Validation failed: {}", ex.getMessage());

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.

MethodArgumentNotValidException에서 ex.getMessage()를 그대로 WARN에 남기면 rejected value가 로그에 섞일 수 있습니다. 회원가입/로그인 같은 검증 실패에서 사용자 입력값이 그대로 남을 수 있어서, 고정 문구나 field name / error count 정도만 남기는 쪽이 더 안전해 보입니다.

return ResponseEntity.notFound().build();
}
log.error("No static resource {}", exception.getResourcePath(), exception);
log.warn("No static resource: {}", exception.getResourcePath());

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.

PR 설명 수정이 필요해보입니다. 본문에는 “봇 스캔성 404 등 고빈도 노이즈는 DEBUG”라고 적혀 있는데, 현재 구현은 NoResourceFoundExceptionWARN으로 남기고 있습니다.

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.

예외 레벨 정책 정립: 예상 가능한 4xx 와 실제 5xx 분리

2 participants