After (finally) Advice
Details as well as Examples covering After Advice.
package org.example.logging;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;
@Slf4j
@Aspect
@Component
public class LoggingAspect {
private static final String AFTER_POINTCUT ="execution(* org.example.controller.*.*(..))";
@After(value = AFTER_POINTCUT)
public void logsErrors(JoinPoint joinPoint){
// Log the controller name
log.info("After - {}", joinPoint.getSignature().getName());
// Log the exception message
log.info("After - {}", joinPoint.getArgs());
}
}

Last updated