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

It seems that you have one extra closing parenthesis before “;” on line 8.


From: aspectj-users-bounces@xxxxxxxxxxx [mailto:aspectj-users-bounces@xxxxxxxxxxx] On Behalf Of Wim Deblauwe
Sent: Tuesday, June 06, 2006 9:47 AM
To: aspectj-users@xxxxxxxxxxx
Subject: Re: [aspectj-users] Logging enabled check idea


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?



2006/6/6, Wim Deblauwe <wim.deblauwe@xxxxxxxxx>:


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.


     logger.info("Entering application." + (i++));
     Bar bar = new Bar();

     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?



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.

public class LoggingAspect {
    @Around("call (* Logger.debug(..)) && target(log) &&
    public void isDebugEnabled(ProceedingJoinPoint thisJoinPoint,
Logger log) throws Throwable {
        if (log.isDebugEnabled ()) {

/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