/**
 * @description:    记录接口执行时间日志的记录
 * @author: 
 * @create 2018-12-27 16:32
 */
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface OptimizeLog {
}

 

package com.wsh.b2q.pc.aspectj;

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.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;


/**
 * @description:
 * @author: lvws
 * @create 2018-12-27 16:34
 */
@Aspect
@Component
@Slf4j
public class OptimizeLogAspect {
    @Pointcut("@annotation(OptimizeLog的路径)")
    public void logPointCut() {

    }

    @Around("logPointCut()")
    public Object around(ProceedingJoinPoint point) throws Throwable {
        //开始时间
        long start = System.currentTimeMillis();
        //执行方法
        Object result = point.proceed();
        long end = System.currentTimeMillis();
        MethodSignature signature = (MethodSignature) point.getSignature();

        //请求的方法名
        String className = point.getTarget().getClass().getName();
        String methodName = signature.getName();
        log.debug("【接口执行时间】接口名:{}.{},执行时间:{}毫秒",className,methodName,(end-start));
        log.info("【接口执行时间】接口名:{}.{},执行时间:{}毫秒",className,methodName,(end-start));
        return result;
    }

}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-01
猜你喜欢
  • 2021-09-25
  • 2022-12-23
  • 2022-12-23
  • 2021-05-26
  • 2021-11-08
  • 2022-12-23
  • 2019-12-26
相关资源
相似解决方案