From 37cc442f12a394bcd3a8d9caf3b1191fee9fad15 Mon Sep 17 00:00:00 2001 From: Jangan Lee Date: Fri, 15 Nov 2024 01:13:08 +0900 Subject: [PATCH] =?UTF-8?q?[Weekly/11/Feature/LoggingAOP]=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=ED=98=B8=EC=B6=9C=20Logger=20AOP=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20(#136)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cokaen/wouldyouin/_common/aop/Logger.java | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/main/java/org/ktc2/cokaen/wouldyouin/_common/aop/Logger.java diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/aop/Logger.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/aop/Logger.java new file mode 100644 index 00000000..52d9e4e1 --- /dev/null +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/aop/Logger.java @@ -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; + } +}