Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] Question on Tracing

Hi All,

I'm new to Aspect J. I wrote my first aspect using
Aspect J for tracing. I would like to log a message
upon entry and exit of all the methods in ALL the
packages in my project.

I've a class called EspressoLog as follows:

public class EspressoTrace {

        private static Logger logger = null;

        public static void initLogger(Logger l) {
                logger = l;
        }
        public static void traceEntry(String message)
{
                logger.debug("Entering : " + message);
        }

        public static void traceExit(String message) {
                logger.debug("Exiting : " + message);
        }
}

I've another class as follows

aspect EspressoTraceAspect {
        
        private Logger logger;
        
                
        pointcut traceCall() : target(*) &&
execution(public *
com.apple.ist.espresso.xmlparser..*(..));
        
        before() : traceCall() {
               
EspressoTrace.initLogger(EspressoLogger.getLogger(thisJoinPointStaticPart.getSignature().getName().getClass()));
                EspressoTrace.traceEntry("" +
thisJoinPointStaticPart.getSignature().getName());
        }
                
        after() : traceCall() {
                EspressoTrace.traceExit("" +
thisJoinPointStaticPart.getSignature().getName());
        }

}


My problem is that i'm calling initLogger every time
in before method of my EspressoTraceAspect. But the
efficient way to do this is to call only once per
invocation of a class not before the invocation of
each method in that class. how can i achieve this?


Also, if the same class is called through multiple
threads having the Logger attribute as static in
EspressoTraceAspect would not help. How should i
handle that?

Thanks for any input in advance,
Manjula

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


Back to the top