diff options
Diffstat (limited to 'sandbox/rfeng/aop-logging')
2 files changed, 41 insertions, 9 deletions
diff --git a/sandbox/rfeng/aop-logging/src/main/java/org/apache/tuscany/sca/aspectj/TracingAspect.java b/sandbox/rfeng/aop-logging/src/main/java/org/apache/tuscany/sca/aspectj/TracingAspect.java index 7a6e4c5ded..53ef73573b 100644 --- a/sandbox/rfeng/aop-logging/src/main/java/org/apache/tuscany/sca/aspectj/TracingAspect.java +++ b/sandbox/rfeng/aop-logging/src/main/java/org/apache/tuscany/sca/aspectj/TracingAspect.java @@ -21,6 +21,8 @@ package org.apache.tuscany.sca.aspectj; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.annotation.After; +import org.aspectj.lang.annotation.AfterReturning; +import org.aspectj.lang.annotation.AfterThrowing; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.aspectj.lang.annotation.Pointcut; @@ -61,23 +63,35 @@ public abstract class TracingAspect { } @Before("trace() && supportsAfterAdvice()") - public void beforeTrace(JoinPoint.StaticPart jp) { + public void beforeTrace(JoinPoint jp) { logEnter(jp); } @After("trace() && supportsAfterAdvice()") - public void afterTrace(JoinPoint.StaticPart jp) { + public void afterTrace(JoinPoint jp) { logExit(jp); } + + @AfterReturning(pointcut = "trace() && supportsAfterAdvice()", returning = "result") + public void afterReturning(JoinPoint jp, Object result) { + logExit(jp, result); + } + + @AfterThrowing(pointcut = "trace() && supportsAfterAdvice()", throwing = "e") + public void afterThrowing(JoinPoint jp, Throwable e) { + logException(jp, e); + } @After("start()") public void afterStart() { completeLog(); } - protected abstract void logEnter(JoinPoint.StaticPart jp); + protected abstract void logEnter(JoinPoint jp); - protected abstract void logExit(JoinPoint.StaticPart jp); + protected abstract void logExit(JoinPoint jp); + protected abstract void logExit(JoinPoint jp, Object result); + protected abstract void logException(JoinPoint jp, Throwable throwable); protected abstract void startLog(); diff --git a/sandbox/rfeng/aop-logging/src/test/java/org/apache/tuscany/sca/aspectj/MyTracingAspect.java b/sandbox/rfeng/aop-logging/src/test/java/org/apache/tuscany/sca/aspectj/MyTracingAspect.java index 7c04341718..3d70d03365 100644 --- a/sandbox/rfeng/aop-logging/src/test/java/org/apache/tuscany/sca/aspectj/MyTracingAspect.java +++ b/sandbox/rfeng/aop-logging/src/test/java/org/apache/tuscany/sca/aspectj/MyTracingAspect.java @@ -19,7 +19,9 @@ package org.apache.tuscany.sca.aspectj; -import org.aspectj.lang.JoinPoint.StaticPart; +import java.util.Arrays; + +import org.aspectj.lang.JoinPoint; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Pointcut; @@ -38,22 +40,38 @@ public class MyTracingAspect extends TracingAspect { System.out.println("completeLog()"); } - @Pointcut("execution(public * org.apache.tuscany.sca..*.*(..))") + @Pointcut("execution(public * org.apache.tuscany.sca..*.*(..)) &&!within(java..*)") protected void entry() { } - + @Pointcut("within(org.apache.tuscany.sca..*) && !within(org.apache.tuscany.sca.aspectj.*Aspect)") protected void withinScope() { } @Override - protected void logEnter(StaticPart jp) { + protected void logEnter(JoinPoint jp) { System.out.println("> " + jp.getSignature()); + if (jp.getArgs().length != 0) { + System.out.println("Input: " + Arrays.asList(jp.getArgs())); + } + } + + @Override + protected void logExit(JoinPoint jp) { + // System.out.println("> " + jp.getSignature()); + } + + @Override + protected void logException(JoinPoint jp, Throwable throwable) { + System.out.println("! " + jp.getSignature() + " " + throwable.getMessage()); } @Override - protected void logExit(StaticPart jp) { + protected void logExit(JoinPoint jp, Object result) { System.out.println("< " + jp.getSignature()); + if (!jp.getSignature().toString().startsWith("void ")) { + System.out.println("Output: " + result); + } } @Override |