Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[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 I’m 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