Hi to all,
I am pretty new to AspectJ and was wondering about a thing…
I saw some nice examples like logging methods the start and the end. In that example there was just an System.out used. I was trying that using log4j but did not get along directly.
After some googling I found a kind of reflective workaround so it looks like this;
import
org.apache.log4j.Logger;
import
org.aspectj.lang.Signature;
import
de.lala.Klasse1
import
de.lala.Klasse2;
import
de.lala.Klasse3;
public aspect Performance
{
pointcut classes()
: within(Klasse1)
|| within
(Klasse2)
|| within(Klasse3);
pointcut constructors()
: classes()
&& execution(new(..));
pointcut methods()
: classes()
&& execution
(*
*(..));
before
()
: constructors()
|| methods()
{
Signature
sig = thisJoinPointStaticPart.getSignature();
Logger logger
= Logger.getLogger(sig.getDeclaringType());
logger.info("-----
start:"+sig);
}
after
()
: constructors()
|| methods()
{
Signature
sig = thisJoinPointStaticPart.getSignature();
Logger logger
= Logger.getLogger(sig.getDeclaringType());
logger.info("-----
end:"+sig);
}
}
The disadvantage is that I need the aspect-library to run my program.
Is there any way to use the static logger field provided in eaqch class of its own for the advice? If yes, what is the correct syntax for that?
Thanks for useful hints in advance
Malte