AOP логирование
This commit is contained in:
@@ -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')
|
||||
}
|
||||
|
||||
30
src/main/java/ru/di9/mirror/aspect/LoggerAspect.java
Normal file
30
src/main/java/ru/di9/mirror/aspect/LoggerAspect.java
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user