package com.yeshi.buwan.aspect;
|
|
import com.yeshi.buwan.log.LogHelper;
|
import net.sf.ehcache.CacheManager;
|
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;
|
|
@Component
|
@Aspect()
|
public class LogAspect {
|
private final Logger logger = LoggerFactory.getLogger(LogAspect.class);
|
|
private String getMethodName(ProceedingJoinPoint pjp) {
|
try {
|
MethodSignature sig = (MethodSignature) pjp.getSignature();
|
Method method = sig.getMethod();
|
return method.getDeclaringClass().getName() + "." + sig.getMethod().getName();
|
} catch (Exception e) {
|
return "";
|
}
|
}
|
|
@Around("execution(public * com.yeshi.buwan.controller.parser.*.*(..))")
|
public Object countTime(ProceedingJoinPoint joinPoint) {
|
|
Object[] args = joinPoint.getArgs();
|
long starttime = System.currentTimeMillis();
|
Object obj = null;
|
try {
|
obj = joinPoint.proceed(args);
|
} catch (Throwable e) {
|
logger.error("客户端接口访问出错:", e);
|
}
|
LogHelper.countTime(getMethodName(joinPoint) + "#" + (System.currentTimeMillis() - starttime) + "");
|
return obj;
|
}
|
|
// @Around("execution(public * com.yeshi.buwan.controller.parser.*(..))")
|
public Object statisticEhcache(ProceedingJoinPoint joinPoint) {
|
Object[] args = joinPoint.getArgs();
|
long starttime = System.currentTimeMillis();
|
Object obj = null;
|
try {
|
obj = joinPoint.proceed(args);
|
} catch (Throwable e) {
|
e.printStackTrace();
|
}
|
LogHelper.countTime(getMethodName(joinPoint));
|
CacheManager manager = CacheManager.newInstance("src/ehcache.xml");
|
// manager.
|
// Cache test = manager.getCache("testCache");
|
return obj;
|
}
|
|
}
|