[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Fixing logger.debug(expensiveObject.toString())

Title: Dean Wampler's Signature
Scott Hayward wrote:
[snip]

I could put wrap the toString method of expensive objects with around
advice and replace the expensive operation if I'm not debugging. But this
only works if the sole reason to evaluate the expensive toString() is for
debug logging and *nothing* else. So if the application uses the same
toString() method elsewhere, the solution cannot be used.

      public pointcut insideToString() :
            call(* sandbox.BigUglyLogger.toString());

      String around() : insideToString()
      {
            if (BigUglyLogger.isDebug())
            {
                  return proceed();
            }
            return thisJoinPointStaticPart.getSignature().toShortString();
      }

Have I missed another approach?

[snip]
  
Could you determine from the control flow context whether or not to evaluate "toString()". Say, for example, you want to circumvent it when "cflow (call (* Foo.bar(..))" is true? Perhaps, even "within" or "withincode" could be used. Or, can you use an "if()" in the pointcut definition to determine the appropriate action to take?

dean

--
Dean Wampler, Ph.D.
dean at aspectprogramming.com
http://www.aspectprogramming.com
http://www.contract4j.org
I want my tombstone to say:
Unknown Application Error in Dean Wampler.exe.
Application Terminated.