@Aspect
@Component
@Slf4j
public class ControllerAspact {
@Pointcut("execution(public * com.example.controller..*.*(..))")
public void requestLog() {
}
@Before("requestLog()")
public void doBefore(JoinPoint joinPoint) {
if (log.isDebugEnabled()) {
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = attributes.getRequest();
log.debug("url={}", request.getRequestURL());
log.debug("method={}", request.getMethod());
log.debug("class_method={}", joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName());
log.debug("args={}", Arrays.toString(joinPoint.getArgs()));
}
}
@AfterReturning(returning = "object", pointcut = "requestLog()")
public void doAfterReturning(Object object) {
log.info("response={}", object == null ? null : object.toString());
}
}