Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Method parameter creation...

Sorry, this would be great, but AspectJ doesn't work that way.
 
The short story is that the parameter evaluation happens before the call join point,
before any advice could short-circuit.  There's a longer discussion if you search
the mail archive for "parameter evaluation", e.g.,
 
 
Personally, I combine log API's with standard rendering; there aren't too
many variants:
 
   log(String label)
   log(String label, Object item)
   log(String label, Object[] items)
 
Then my advice or a pluggable renderer can decide how/when to evaluate
the arguments.  But this doesn't help for existing code.
 
Wes
 
 
------------Original Message------------
From: Parag Desai <talktoparag@xxxxxxxxx>
To: aspectj-users@xxxxxxxxxxx
Date: Sun, Jul-18-2004 10:04 PM
Subject: [aspectj-users] Method parameter creation...

Hi,

 

I need a small clarification.

 

In my project, there is a requirement to check for the log level before actually logging. Like this:

 

if ( logger.isDebugEnabled() )

{

            logger.debug(This is logged);

}

 

We wanted to automate the level check using AspectJ. Hence, I wrote an aspect like

 

pointcut debug() : call(* *.debug(..));

 

void around(): debug()

{

            if ( logger.isDebugEnabled() )

                        proceed();

}

 

The code that I wrote to test this is:

 

public static void testDebug()

{

debug( "This is logged );

}

 

When I decompiled the class file generated, I found the following code:

 

public static void testDebug()

{

String s = "This is logged";

debug_aroundBody1$advice(s, TestAspect.aspectOf(), null);

} // where TestAspect was the name of my Aspect.

 

Now the intention of checking log level is to avoid the overhead of method parameter creation when the method is not going to be executed. The String This is logged is created irrespective of whether or not the conditional check in the advice is satisfied. Is this a drawback of AspectJ? Is there a workaround? Please tell me, as I am just a beginner in AspectJ and Im doing the first and only AspectJ-enabled project in my company.

 

With warm regards

 -Parag

 

(talktoparag@xxxxxxxxx, DParagp@xxxxxxxxxxxxxxxxx)


Do you Yahoo!?
Vote for the stars of Yahoo!'s next ad campaign!

Back to the top