I am trying to make something very simple. I have a class com.mypackage.Logger logger, the instance operator of which I would like to "insert" into each individual class: private static Logger LOG = new Logger(Class.class) . Then I would like to write each instance of the record and exit for each individual function in my project. Here is my aspect:
public aspect LoggingAspect pertypewithin(*) { private static Logger LOG; pointcut classes(): within(com.mypackage..*) && !within(com.mypackage.Logger) && !within(com.mypackage.LoggingAspect); pointcut functions(): classes() && (execution(* *(..)) || execution(new(..))); before(): staticinitialization(*) && classes() { LOG = new Logger(thisJoinPointStaticPart.getSignature().getDeclaringType()); } before() : functions() { LOG.trace("ENTER " + thisJoinPoint.getSignature().toLongString()); } after() returning(@SuppressWarnings("unused") Object ret) : functions() { LOG.trace("EXIT " + thisJoinPoint.getSignature().toLongString()); }
Almost everything is working correctly. I get the correct input and the presence of the log statements exactly as expected. The problem is that the log class associated with each log entry is incorrect. I use log4j and each log entry is formatted like this:
[TRACE] (date and time stamp) (log class name) (stream name) (some registration instruction)
The problem is that the logging class used in the instance of the Logger does not match the correct one denoted by thisJoinPoint.getSignature().getDeclaringTypeName() .
I know that I am not doing anything appropriate regarding the Logger static variable, so please help me. thank you for your time!
source share