package com.doc.parser.application.aspect; import cn.hutool.json.JSONUtil; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.reflect.MethodSignature; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; import java.lang.reflect.Method; /** * @author Luke.ye * @date 2025/5/7 15:01 */ @Component @Aspect public class OperationLogAspect { private static final Logger LOGGER = LoggerFactory.getLogger(OperationLogAspect.class); @Around("@annotation(com.doc.parser.application.anno.OperationLog)") public Object logOperation(ProceedingJoinPoint joinPoint) throws Throwable { MethodSignature signature = (MethodSignature) joinPoint.getSignature(); Method method = signature.getMethod(); Object result = null; try { result = joinPoint.proceed(); LOGGER.info("方法名 [{}] , 输入参数: {}, 返回结果: {}", method.getName() , JSONUtil.toJsonStr(joinPoint.getArgs()), JSONUtil.toJsonStr(result)); } catch (Throwable ex) { LOGGER.error("方法名 [{}] 抛出异常: {}", method.getName(), ex.getMessage(), ex); throw ex; } return result; } }