diff --git a/apps/user-service/build.gradle b/apps/user-service/build.gradle index 17c949f3..3596f42d 100644 --- a/apps/user-service/build.gradle +++ b/apps/user-service/build.gradle @@ -30,6 +30,7 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-security' implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:3.0.5' + implementation 'org.springframework.boot:spring-boot-starter-aop' compileOnly 'org.projectlombok:lombok' runtimeOnly 'com.h2database:h2' annotationProcessor 'org.projectlombok:lombok' diff --git a/apps/user-service/src/main/java/com/gltkorea/icebang/aop/logging/LoggingAspect.java b/apps/user-service/src/main/java/com/gltkorea/icebang/aop/logging/LoggingAspect.java new file mode 100644 index 00000000..0441820d --- /dev/null +++ b/apps/user-service/src/main/java/com/gltkorea/icebang/aop/logging/LoggingAspect.java @@ -0,0 +1,54 @@ +package com.gltkorea.icebang.aop.logging; + +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 lombok.extern.slf4j.Slf4j; + +@Slf4j +@Aspect +@Component +public class LoggingAspect { + + @Pointcut("execution(public * com.gltkorea.icebang..controller..*(..))") + public void controllerMethods() {} + + @Pointcut("execution(public * com.gltkorea.icebang..service..*(..))") + public void serviceMethods() {} + + @Pointcut("execution(public * com.gltkorea.icebang..service..repository..*(..))") + public void repositoryMethods() {} + + @Around("controllerMethods()") + public Object logController(ProceedingJoinPoint joinPoint) throws Throwable { + long start = System.currentTimeMillis(); + log.info("[CONTROLLER] Start: {} args={}", joinPoint.getSignature(), joinPoint.getArgs()); + Object result = joinPoint.proceed(); + long duration = System.currentTimeMillis() - start; + log.info("[CONTROLLER] End: {} ({}ms)", joinPoint.getSignature(), duration); + return result; + } + + @Around("serviceMethods()") + public Object logService(ProceedingJoinPoint joinPoint) throws Throwable { + long start = System.currentTimeMillis(); + log.info("[SERVICE] Start: {} args={}", joinPoint.getSignature(), joinPoint.getArgs()); + Object result = joinPoint.proceed(); + long duration = System.currentTimeMillis() - start; + log.info("[SERVICE] End: {} ({}ms)", joinPoint.getSignature(), duration); + return result; + } + + @Around("repositoryMethods()") + public Object logRepository(ProceedingJoinPoint joinPoint) throws Throwable { + long start = System.currentTimeMillis(); + log.debug("[REPOSITORY] Start: {} args={}", joinPoint.getSignature(), joinPoint.getArgs()); + Object result = joinPoint.proceed(); + long duration = System.currentTimeMillis() - start; + log.debug("[REPOSITORY] End: {} ({}ms)", joinPoint.getSignature(), duration); + return result; + } +}