Skip to content

Commit

Permalink
feat: log aop 내용 추가
Browse files Browse the repository at this point in the history
- controller 실행 시간 기록
  • Loading branch information
linglong67 committed Mar 15, 2024
1 parent 6e55dad commit 8f3c396
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions module-api/src/main/java/com/kernel360/global/aop/LogAspect.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Slf4j
Expand All @@ -21,4 +23,21 @@ public Object logExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable {

return proceed;
}

@Pointcut("within(*..*Controller)")
public void controller() {}

@Around("controller()")
public Object logApiExecTime(ProceedingJoinPoint joinPoint) throws Throwable {
long start = System.currentTimeMillis();
Object proceed = joinPoint.proceed();

long executionTime = System.currentTimeMillis() - start;
Signature signature = joinPoint.getSignature();

log.info(String.format("##### @API Execution Time ##### [%dms] → %s.%s",
executionTime, signature.getDeclaringTypeName(), signature.getName()));

return proceed;
}
}

0 comments on commit 8f3c396

Please sign in to comment.