Skip to content

Commit

Permalink
feat: exception AOP 로그 추가 (#241)
Browse files Browse the repository at this point in the history
* feat: ExceptionHandler AOP 적용

* refactor: 수정

* refactor: checkstyle 적용
  • Loading branch information
ymkim97 authored Dec 3, 2023
1 parent fda78e1 commit a4a14ff
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServl
throw new UnauthorizedException(ErrorMessage.INVALID_REQUEST_URL);
}
} catch (UnauthorizedException unauthorizedException) {
log.error("{}, {}", httpServletRequest.getHeader("referer"), allowOriginsConfig.origin());
handlerExceptionResolver.resolveException(httpServletRequest, httpServletResponse, null,
unauthorizedException);

Expand Down
24 changes: 24 additions & 0 deletions src/main/java/com/moabam/global/common/util/LogAspect.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.moabam.global.common.util;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

import lombok.extern.slf4j.Slf4j;

@Aspect
@Slf4j
@Component
public class LogAspect {

@Around("execution(* com.moabam.global.error.handler.GlobalExceptionHandler.*(..))")
public Object printExceptionLog(ProceedingJoinPoint joinPoint) throws Throwable {
Object[] args = joinPoint.getArgs();
Exception exception = (Exception)args[0];

log.error("===== EXCEPTION LOG =====", exception);

return joinPoint.proceed();
}
}

0 comments on commit a4a14ff

Please sign in to comment.