im.aop.loggers.advice.around.LogAroundAdvice Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of im-aop-loggers Show documentation
Show all versions of im-aop-loggers Show documentation
A handy and configurable sets of annotation-based loggers for Spring Boot that can
log every execution of a method when entering or exiting normally or abnormally, without you
writing a single line of code using aspect-oriented programming (AOP)
The newest version!
package im.aop.loggers.advice.around;
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.beans.factory.annotation.Autowired;
/**
* Spring's AOP Advice for {@link LogAround}.
*
* @author Andy Lian
*/
@Aspect
public class LogAroundAdvice {
@Autowired
private LogAroundService logAroundService;
@Pointcut("execution(public * *(..))")
void publicMethod() {
}
@Pointcut("execution(String *.toString())")
void toStringMethod() {
}
@Pointcut(value = "@annotation(logAround)", argNames = "logAround")
void logAroundMethodContext(final LogAround logAround) {
}
@Around(
value = "publicMethod() && logAroundMethodContext(logAround)",
argNames = "joinPoint, logAround")
Object logAroundMethodContext(final ProceedingJoinPoint joinPoint, final LogAround logAround)
throws Throwable {
return logAround(joinPoint, logAround);
}
@Pointcut(value = "@within(logAround)", argNames = "logAround")
void logAroundClassContext(final LogAround logAround) {
}
@Around(
value = "publicMethod() && !toStringMethod() && logAroundClassContext(logAround)",
argNames = "joinPoint, logAround")
Object logAroundClassContext(final ProceedingJoinPoint joinPoint, final LogAround logAround)
throws Throwable {
return logAround(joinPoint, logAround);
}
protected Object logAround(final ProceedingJoinPoint joinPoint, final LogAround logAround)
throws Throwable {
return logAroundService.logAround(joinPoint, logAround);
}
}