diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2008-08-06 16:19:39 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2008-08-06 16:19:39 +0000 |
commit | 9437a5e897404743bd05438357b175626425f850 (patch) | |
tree | 4af980ea29ca71c8cb98e3ed872fcbd296fcd526 /sandbox/rfeng/aop-logging | |
parent | df92933f74b47ded6078f53ea80f054ab919ef04 (diff) |
Display input/output for traces
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@683317 13f79535-47bb-0310-9956-ffa450edef68
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 |