|
|
@@ -1,52 +0,0 @@ |
|
|
|
package com.tuoheng.miniprogram.aspect; |
|
|
|
|
|
|
|
import org.aspectj.lang.ProceedingJoinPoint; |
|
|
|
import org.aspectj.lang.annotation.Around; |
|
|
|
import org.aspectj.lang.annotation.Aspect; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
/** |
|
|
|
* Spring AOP统计请求接口耗时 |
|
|
|
* @Author ChengWang |
|
|
|
* @Date 2023/3/2 |
|
|
|
*/ |
|
|
|
@Component |
|
|
|
@Aspect |
|
|
|
public class ServiceLogAspect { |
|
|
|
|
|
|
|
public static final Logger log = LoggerFactory.getLogger(ServiceLogAspect.class); |
|
|
|
|
|
|
|
/** |
|
|
|
* AOP通知 |
|
|
|
* 1.前置通知:在方法调用之前执行 |
|
|
|
* 2.后置通知:在方法正常调用之后执行 |
|
|
|
* 3.环绕通知:在方法调用之前和之后,都分别可以执行的通知 |
|
|
|
* 4.异常通知:如果在方法调用过程中发生异常,则通知 |
|
|
|
* 5.最终通知:在方法调用之后执行 |
|
|
|
*/ |
|
|
|
@Around("execution(* com.tuoheng.miniprogram.service.impl..*.*(..))") |
|
|
|
public Object recordTimeLog(ProceedingJoinPoint joinPoint) throws Throwable{ |
|
|
|
log.info("========开始执行{}.{}=======", |
|
|
|
joinPoint.getTarget().getClass() |
|
|
|
,joinPoint.getSignature().getName()); |
|
|
|
//service执行时间 |
|
|
|
//记录开始执行时间 |
|
|
|
long begin = System.currentTimeMillis(); |
|
|
|
//执行目标service |
|
|
|
Object result = joinPoint.proceed(); |
|
|
|
//记录结束执行时间 |
|
|
|
long end = System.currentTimeMillis(); |
|
|
|
long takeTime = end - begin; |
|
|
|
if(takeTime>3000){ |
|
|
|
log.error("======执行结束,耗时:{}毫秒======",takeTime); |
|
|
|
}else if(takeTime>2000){ |
|
|
|
log.warn("======执行结束,耗时:{}毫秒======",takeTime); |
|
|
|
}else { |
|
|
|
log.info("======执行结束,耗时:{}毫秒======",takeTime); |
|
|
|
} |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
} |