i want to log all method call i make in my code except the ones within the logger, using AspectJ.
@Aspect
public class Logger
{
// Point Cuts
//-----------
@Pointcut("execution(* org.myDomain.*..*.*(..))")
public void selectAll(){}
@Pointcut("within(Logger) && call(* *(..))")
public void codeWithinAspect(){}
// Advices
//-----------
@Before("selectAll()")
public void adviceThatWorksFine(JoinPoint joinPoint)
{
System.out.print(joinPoint.getSignature().toString());
//Utils.printToConsole(joinPoint.getSignature().toString());
}
@Before("selectAll() && !codeWithinAspect")
public void adviceWithInfiniteLoop(JoinPoint joinPoint)
{
//System.out.print(joinPoint.getSignature().toString());
Utils.printToConsole(joinPoint.getSignature().toString());
}
}
the first advice in the class works fine (it writes every method call to the console), the second advice causes an infinite loop when calling org.myDomain.utils.Utils.printToConsole() method, which is advised by the calling advice.
I have found it is a common problem as described in the link http://www.eclipse.org/aspectj/doc/released/faq.php#q:infiniterecursion but i could not understand how to write the pointcut so an infinite loop would not be created.
plaes help