-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Weekly/11/Feature/LoggingAOP] 메서드 호출 Logger AOP 추가 (#136)
- Loading branch information
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
src/main/java/org/ktc2/cokaen/wouldyouin/_common/aop/Logger.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package org.ktc2.cokaen.wouldyouin._common.aop; | ||
|
||
import jakarta.servlet.http.HttpServletRequest; | ||
import java.net.URLDecoder; | ||
import java.util.Enumeration; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import lombok.extern.slf4j.Slf4j; | ||
import net.minidev.json.JSONObject; | ||
import org.aspectj.lang.ProceedingJoinPoint; | ||
import org.aspectj.lang.annotation.Around; | ||
import org.aspectj.lang.annotation.Aspect; | ||
import org.aspectj.lang.annotation.Pointcut; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.context.request.RequestContextHolder; | ||
import org.springframework.web.context.request.ServletRequestAttributes; | ||
|
||
@Slf4j | ||
@Aspect | ||
@Component | ||
public class Logger { | ||
|
||
@Pointcut("execution(* org.ktc2.cokaen.wouldyouin.auth.application.JwtAuthFilter.*(..))") | ||
public void springFilterExecution() { | ||
} | ||
|
||
@Pointcut("execution(* org.ktc2.cokaen.wouldyouin..*.*(..)) && !springFilterExecution()") | ||
public void all() { | ||
} | ||
|
||
@Around("all()") | ||
public Object logging(ProceedingJoinPoint joinPoint) throws Throwable { | ||
String methodName = joinPoint.getSignature().toShortString(); | ||
String packageName = joinPoint.getSignature().getDeclaringTypeName() | ||
.replace("org.ktc2.cokaen.wouldyouin.", "") | ||
.replaceAll("\\.[^\\.]+$", ""); | ||
Object[] args = joinPoint.getArgs(); | ||
long start = System.currentTimeMillis(); | ||
long timeInMs; | ||
Object result; | ||
log.debug("{} : CALL {}", packageName, methodName); | ||
log.debug("{} : with param = {}", packageName, args); | ||
|
||
try { | ||
result = joinPoint.proceed(); | ||
} catch(Throwable t) { | ||
log.debug("{} : {} throws {}", packageName, methodName, t.getClass().getSimpleName()); | ||
throw t; | ||
} finally { | ||
timeInMs = System.currentTimeMillis() - start; | ||
log.debug("{} : EXIT {}", packageName, methodName); | ||
log.debug("{} : with executeTime = {}ms", packageName, timeInMs); | ||
} | ||
|
||
log.debug("{} : with return = {}", packageName, result); | ||
|
||
return result; | ||
} | ||
} |