package com.xyz.axy.aspect;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import com.xyz.axy.domain.entity.WeuiEntity;
@Aspect
@Component
public class LogAspect {
private final static Logger logger=LoggerFactory.getLogger(LogAspect.class);
@Pointcut("execution(* com.xyz.axy.service.*.*(..))")
public void pointcutName(){}
// @Before("pointcutName()")
// public void before(JoinPoint joinPoint){
// logger.info("before");
// Object[] args =joinPoint.getArgs();
// for (Object object : args) {
// logger.info("before参数:"+object.toString());
// }
// }
@Around("pointcutName()")
public Object around(ProceedingJoinPoint joinPoint) {
logger.info("========获取参数开始=========");
Object[] args = joinPoint.getArgs();
for (Object object : args) {
if (object instanceof WeuiEntity) {
WeuiEntity we = (WeuiEntity) object;
logger.info(we.getMsg());
logger.info(we.getTitle());
} else {
logger.info("around参数:" + object.toString());
}
}
logger.info("========获取参数结束=========");
Object result = null;
logger.info("around1");
try {
result = joinPoint.proceed();
} catch (Throwable e) {
e.printStackTrace();
}
logger.info("around2");
return result;
}
// @After("pointcutName()")
// public void after(JoinPoint joinPoint) {
// logger.info("after");
// Object[] args =joinPoint.getArgs();
// for (Object object : args) {
// logger.info("after参数:"+object.toString());
// }
// }
}