|
@@ -0,0 +1,43 @@
|
|
|
+package com.jwkj.qsydw.aspect;
|
|
|
+
|
|
|
+import com.jwkj.qsydw.annotation.Loggable;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+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.stereotype.Component;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author Xu·LinPeng
|
|
|
+ */
|
|
|
+@Aspect
|
|
|
+@Component
|
|
|
+@Slf4j
|
|
|
+public class LoggingAspect {
|
|
|
+
|
|
|
+ //切点:使用LogAnnotation注解标识的方法都进行切入,也可以使用通配符配置具体要切入的方法名
|
|
|
+ @Pointcut("@annotation(loggable)")
|
|
|
+ public void pointCut(Loggable loggable){
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Around(value = "pointCut(loggable)", argNames = "joinPoint,loggable")
|
|
|
+ public Object logMethod(ProceedingJoinPoint joinPoint, Loggable loggable) throws Throwable {
|
|
|
+// MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
|
|
+// String methodName = signature.getMethod().getName();
|
|
|
+// String className = joinPoint.getTarget().getClass().getSimpleName();
|
|
|
+// Object[] args = joinPoint.getArgs();
|
|
|
+
|
|
|
+ log.info("{}被调用",loggable.value());
|
|
|
+ try {
|
|
|
+ Object result = joinPoint.proceed();
|
|
|
+ log.info("{}调用成功",loggable.value());
|
|
|
+ return result;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("{} 调用失败,错误信息:{}",loggable.value(),e.getMessage());
|
|
|
+ throw e;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|