用springboot实现操作日志,我要代码
时间: 2023-03-15 12:50:49 浏览: 110
基于springboot实现个人博客的源代码
您可以使用以下代码来实现操作日志:@Component
public class LoggingAspect {
private Logger logger = LoggerFactory.getLogger(this.getClass());
@Around("execution(* com.example.demo.service.*.*(..))")
public Object logServiceAccess(ProceedingJoinPoint joinPoint) throws Throwable {
long startTime = System.currentTimeMillis();
Object result = joinPoint.proceed();
String className = joinPoint.getSignature().getDeclaringTypeName();
String methodName = joinPoint.getSignature().getName();
Object[] args = joinPoint.getArgs();
long duration = System.currentTimeMillis() - startTime;
logger.info("Class: {}, Method: {}, Args: {}, Duration: {}ms",
className, methodName, Arrays.toString(args), duration);
return result;
}
}
阅读全文