diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/global/log/LoggingComponent.java b/backend/core/src/main/java/site/timecapsulearchive/core/global/log/LoggingComponent.java index a41394f7..b9674451 100644 --- a/backend/core/src/main/java/site/timecapsulearchive/core/global/log/LoggingComponent.java +++ b/backend/core/src/main/java/site/timecapsulearchive/core/global/log/LoggingComponent.java @@ -2,7 +2,9 @@ import lombok.extern.slf4j.Slf4j; import org.aspectj.lang.JoinPoint; +import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.After; +import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.springframework.stereotype.Component; @@ -12,25 +14,40 @@ @Component public class LoggingComponent { - @Before("execution(* site.timecapsulearchive..*(..)) " - + "&& !within(site.timecapsulearchive.core.infra..config..*)" - + "&& !within(site.timecapsulearchive.core.domain..api..*)" - + "&& !within(site.timecapsulearchive.core.global..*)" - + "|| within(site.timecapsulearchive.core.global.api.limit.ApiLimitCheckInterceptor)" - + "|| within(site.timecapsulearchive.core.global.geography.GeoTransformManager)") - public void doTraceBefore(JoinPoint joinPoint) { - Object[] args = joinPoint.getArgs(); + @Around("execution(public * site.timecapsulearchive.core.domain.*.service.*.*(..))") + public Object logServiceLayer(ProceedingJoinPoint joinPoint) throws Throwable { + return logMethod(joinPoint, "Service"); + } + + @Around(""" + execution(public * site.timecapsulearchive.core.domain.*.repository.*.*(..)) + && (@target(org.springframework.stereotype.Repository) || + target(org.springframework.data.repository.Repository+)) + """) + public Object logRepositoryLayer(ProceedingJoinPoint joinPoint) throws Throwable { + return logMethod(joinPoint, "Repository"); + } + + @Around("execution(public * site.timecapsulearchive.core.infra.*.manager.*.*(..))") + public Object logExternalApi(ProceedingJoinPoint joinPoint) throws Throwable { + return logMethod(joinPoint, "External API"); + } - log.info("[before] {} args={}", joinPoint.getSignature(), args); + @Around("execution(public * site.timecapsulearchive.core.global.api.limit.ApiLimitCheckInterceptor.*(..))") + public Object logApiLimitCheckInterceptor(ProceedingJoinPoint joinPoint) throws Throwable { + return logMethod(joinPoint, "API Limit Check"); } - @After("execution(* site.timecapsulearchive..*(..)) " - + "&& !within(site.timecapsulearchive.core.infra..config..*)" - + "&& !within(site.timecapsulearchive.core.domain..api..*)" - + "&& !within(site.timecapsulearchive.core.global..*)" - + "|| within(site.timecapsulearchive.core.global.api.limit.ApiLimitCheckInterceptor)" - + "|| within(site.timecapsulearchive.core.global.geography.GeoTransformManager)") - public void doTraceAfter(JoinPoint joinPoint) { - log.info("[after] {}", joinPoint.getSignature()); + private Object logMethod(ProceedingJoinPoint joinPoint, String layer) throws Throwable { + String methodName = joinPoint.getSignature().getName(); + log.info("{} Layer - Method {} - Start", layer, methodName); + long startTime = System.currentTimeMillis(); + + Object result = joinPoint.proceed(); + + long endTime = System.currentTimeMillis(); + log.info("{} Layer - Method {} - End, Execution Time: {}ms", layer, methodName, (endTime - startTime)); + + return result; } } \ No newline at end of file