View Javadoc
1   package gboat2.base.logging.aspectj;
2   
3   import org.aspectj.lang.ProceedingJoinPoint;
4   import org.slf4j.Logger;
5   import org.slf4j.LoggerFactory;
6   
7   /**
8    * 
9    * 截取所有的service,为调用的方法 追加 日志
10   * 环绕通知
11   * @author zhangxj-a
12   * @since jdk1.6
13   * @date 2012-4-24
14   *  
15   */
16  public final class LogServiceAspectJ implements ILogServiceAspectJ {
17  	
18  	public LogServiceAspectJ() {
19  		super();
20  	}
21  	
22  	private static final Logger logger = LoggerFactory.getLogger(LogServiceAspectJ.class.getName());
23  	
24  	@Override
25  	public Object invoke(ProceedingJoinPoint pjp) throws Throwable {
26  		//service类名
27  		String serviceName = pjp.getTarget().getClass().getName();
28  		//调用的方法类名
29  		String methodName = pjp.getSignature().getName();
30  		
31  		long startTime = System.currentTimeMillis();
32  		
33  		logger.debug(" Begin Call Service {},Visit method {}  ", new String[] { serviceName, methodName });
34  		//执行service方法
35  		Object ret = pjp.proceed();
36  		
37  		long endTime = System.currentTimeMillis();
38  		
39  		logger.debug(" End   Call Service {},Visit method {} , cost {} ms  ", new String[] { serviceName, methodName,
40  		        String.valueOf(endTime - startTime) });
41  		
42  		return ret;
43  	}
44  	
45  	public int getOrder() {
46  		return Integer.MAX_VALUE;
47  	}
48  	
49  }