AOP логирование

This commit is contained in:
2022-04-25 17:33:12 +03:00
parent e66f1d9451
commit e2fc75877d
2 changed files with 31 additions and 0 deletions

View File

@@ -21,6 +21,7 @@ dependencies {
annotationProcessor('org.springframework.boot:spring-boot-configuration-processor')
implementation('org.springframework.boot:spring-boot-starter-web')
implementation('org.springframework.boot:spring-boot-starter-aop')
implementation('com.squareup.okhttp3:okhttp:4.9.3')
}

View File

@@ -0,0 +1,30 @@
package ru.di9.mirror.aspect;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;
@Slf4j
@Aspect
@Component
public class LoggerAspect {
@Around("execution(* ru.di9.mirror.controller.MavenController.*(..))")
public Object logAroundMavenController(ProceedingJoinPoint joinPoint) throws Throwable {
return logAround(joinPoint);
}
@Around("execution(* ru.di9.mirror.controller.IndexOfMavenController.*(..))")
public Object logAroundIndexOfMavenController(ProceedingJoinPoint joinPoint) throws Throwable {
return logAround(joinPoint);
}
private Object logAround(ProceedingJoinPoint joinPoint) throws Throwable {
log.info("[ASPECT] enter {} <- {}", joinPoint.getSignature().toLongString(), joinPoint.getArgs());
Object result = joinPoint.proceed();
log.info("[ASPECT] exit {} -> [{}]", joinPoint.getSignature().toLongString(), result);
return result;
}
}