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
------------------------------------------------------------------------------------------------ Disclaimer: The contents of this electronic mail message are only binding upon Equens or its affiliates, if the contents of the message are accompanied by a lawfully
recognised type of signature. The contents of this electronic mail message are privileged and confidential and are intended only for use by the addressee. If you have received this electronic mail message by error, please notify the sender and delete the message
without taking notices of its content, reproducing it and using it in any way. ------------------------------------------------------------------------------------------------