基本aop代码
@Aspect
public class LoggingAspect {
private Logger logger ;
@Before("execution(* *(..)) && !execution(* com.*model*.*(..))")
public void logBefore(JoinPoint joinPoint) {
logger = LoggerFactory.getLogger(joinPoint.getTarget().getClass());
logger.info("{} :" + joinPoint.getSignature().getName(),"info for user log" );
//logger.info("hijacked target class : " + joinPoint.getTarget().getClass().getSimpleName() );
}
@After("execution(* *(..)) && !execution(* com.*model*.*(..)) ")
public void logAfter(JoinPoint joinPoint) {
System.out.println("logAfter() is running!");
System.out.println("hijacked : " + joinPoint.getSignature().getName());
System.out.println("******");
}
}
目前,我默认为某些方法实现 aop 日志记录,例如方法开始和方法结束。所以使用 aop logger 打印 apo 类和方法,而不是打印方法拥有的类和方法。我必须覆盖 aop 中的类名来打印该方法的类名,所以我需要将方法名作为本机方法名
目前我正在
2017-09-20 18:32:06 INFO [main] cmcustomer.bo.impl.CustomerBoImpl - logBefore:用户日志信息():addCustomer
我需要的是
2017-09-20 18:32:06 INFO [main] cmcustomer.bo.impl.CustomerBoImpl - addCustomer:用户日志信息():addCustomer