Skip to content

Commit

Permalink
Merge pull request #648 from tukcomCD2024/fix/logging-B-core-#645
Browse files Browse the repository at this point in the history
fix : 로깅 방식 변경 #645
  • Loading branch information
seokho-1116 authored Aug 22, 2024
2 parents 1c389e2 + 3109312 commit fb3b3b3
Showing 1 changed file with 34 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
}

0 comments on commit fb3b3b3

Please sign in to comment.