[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Logging enabled check idea

On 06/06/06, Vincent Jorrand <vjorrand@xxxxxxxxx> wrote:


But the string concatenation will not be avoided.
    logger.debug("error: " + errorMessage);
is equivalent to:
    String debugMessage = "error: " + errorMessage;
    logger.debug(debugMessage);
Only the call to the debug operation is wrapped by the around advice.

Vincent


Yeah. you are right. The around advise I made will as you show above really do nothing else than move the if test from the log.debug method in log4J to the calling class, and thus not add any benefit.

/Kaare


----- Original Message ---- From: Wim Deblauwe <wim.deblauwe@xxxxxxxxx> To: Vincent Jorrand <vjorrand@xxxxxxxxx>; aspectj-users@xxxxxxxxxxx Sent: Tuesday, June 6, 2006 1:22:12 PM Subject: Re: [aspectj-users] Logging enabled check idea

The idea of this check is that it avoids the string concatenation that is
usally happening during logging.

You are right this might not provide a benifit in all situations. This is
more a test case to see what aspectj can do. It would be interesting to
benchmark this a bit to find out if it could provide a benifit.

Anyway, as I said, it is all about learning aspectj for me.

regards,

Wim

2006/6/6, Vincent Jorrand <vjorrand@xxxxxxxxx >:
>
>
>
>
> This is not really adressing the question, but the main purpose of the
call to check the logging level before the call to the logger is to avoid
the cost of the creation of the error message. The proposed solution will
not aleviate it, as it will only wrap the actual call tio the logging
operation. In fact (at least for log4j) it will add cost, and no benefit as
the first thing log4j does is check the logging level.
>
> I do not know of any AspectJ solution that would be provide something
useful to this problem. If someone has one I would actually really like to
learn about it, and would probably implement it.
>
>
> Vincent
>
>
>
>
> ----- Original Message ----
> From: Andy Clement <andrew.clement@xxxxxxxxx>
> To: aspectj-users@xxxxxxxxxxx
>
> Sent: Tuesday, June 6, 2006 1:06:53 PM
> Subject: Re: [aspectj-users] Logging enabled check idea
>
>
> you haven't specified the return type of the around advice.
>
>
> On 06/06/06, Wim Deblauwe < wim.deblauwe@xxxxxxxxx > wrote:
> >
> > Hmmm... I try to convert this to aspectj syntax, and tried this:
> >
> > package test;
> >
> > import org.apache.log4j.Logger;
> >
> > public aspect LoggingAspect {
> >     pointcut debugLogging():(call(* Logger.debug(..))
> >             && target( Logger ))
> >             && !within( LoggingAspect ));
> >
> >     around(): debugLogging( Logger logger ){
> >         if( logger.isDebugEnabled() )
> >         {
> >             thisJoinPoint.proceed ();
> >         }
> >     }
> > }
> >
> > But I keep getting an exception: Syntax error on token ";" on line 8
(that is the line with 'within'). What is wrong?
> >
> > regards,
> >
> > Wim
> >
> >
> > 2006/6/6, Wim Deblauwe <wim.deblauwe@xxxxxxxxx>:
> >
> > >
> > > Hey,
> > >
> > > thanks for the reply! I will check if that works. Maybe we can check
the string creation as follows:
> > >
> > > public class MyApp {
> > >
> > > // Define a static logger variable so that it references the
> > >
> > >
> > >
> > > // Logger instance named "MyApp".
> > >
> > > static Logger logger = Logger.getLogger(MyApp.class);
> > >
> > > public static void main(String[] args) {
> > >
> > > int i = 0;
> > >
> > >
> > >
> > > // Set up a simple configuration that logs on the console.
> > >
> > > BasicConfigurator.configure();
> > >
> > > logger.info("Entering application." + (i++));
> > > Bar bar = new Bar();
> > >
> > >
> > >
> > > bar.doIt();
> > > logger.info("Exiting application." + (i++));
> > >
> > >
> > > System.out.println( "i = " i );
> > > }
> > > }
> > > If i is 2, then the string was created, if it is 0, it works
perfectly, right?
> > >
> > > regards,
> > >
> > > Wim
> > >
> > >
> > >
> > > 2006/6/6, Kaare Nilsen <kaare.nilsen@xxxxxxxxx >:
> > >
> > > > Would this do the trick ?
> > > > It will for sure hit regarding to the pointcut, but not quite shure
if
> > > > it will actually save the construction of the string.
> > > >
> > > > @Aspect
> > > > public class LoggingAspect {
> > > >     @Around("call (* Logger.debug(..)) && target(log) &&
> > > > !within(LoggingAspect)")
> > > >     public void isDebugEnabled(ProceedingJoinPoint
thisJoinPoint,
> > > > Logger log) throws Throwable {
> > > >         if (log.isDebugEnabled ()) {
> > > >             thisJoinPoint.proceed();
> > > >         }
> > > >     }
> > > > }
> > > >
> > > > /Kaare Nilsen
> > > >
> > > > On 06/06/06, Wim Deblauwe < wim.deblauwe@xxxxxxxxx > wrote:
> > > > > Hi,
> > > > >
> > > > > I just had this idea for the use of aspectj, but I don't know if
it is
> > > > > possible:
> > > > >
> > > > > Most of you know that they can check if logging is enabled before
putting
> > > > > the log statement in their code, however, very few do this because
it
> > > > > clutters the code. Would it be possible to define an aspect that
adds all
> > > > > those checks in there (with log4j and/or commons-logging)?
> > > > >
> > > > > Just an idea if someone has some time to spare :)
> > > > >
> > > > > regards,
> > > > >
> > > > > Wim
> > > > >
> > > > > _______________________________________________
> > > > > aspectj-users mailing list
> > > > > aspectj-users@xxxxxxxxxxx
> > > > >
https://dev.eclipse.org/mailman/listinfo/aspectj-users
> > > > >
> > > > >
> > > > >
> > > > _______________________________________________
> > > > aspectj-users mailing list
> > > > aspectj-users@xxxxxxxxxxx
> > > >
https://dev.eclipse.org/mailman/listinfo/aspectj-users
> > > >
> > >
> > >
> > >
> >
> >
> >
> > _______________________________________________
> > aspectj-users mailing list
> > aspectj-users@xxxxxxxxxxx
> > https://dev.eclipse.org/mailman/listinfo/aspectj-users
> >
> >
> >
>
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
>
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
>
>



_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users