Off of the top of my head, I see two quick ways to do this. 1. Reflection. The advice could use reflection to find a field of type Logger and invoke its info method.
2. Introduction. Use an ITD to introduce a Logger known to your advice into the class along with methods to control the logging. HTH, Matthew On Tue, Feb 12, 2013 at 9:11 AM, Kempff, Malte <[email protected]>wrote: > 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<http://www.google.com/search?hl=en&q=allinurl%3Asignature+java.sun.com&btnI=I%27m%20Feeling%20Lucky>sig > = thisJoinPointStaticPart.getSignature(); > > Logger logger = Logger.getLogger(sig.getDeclaringType()); > > logger.info("----- start:"+sig); > > } > > > > after () : constructors() || methods() > > { > > > Signature<http://www.google.com/search?hl=en&q=allinurl%3Asignature+java.sun.com&btnI=I%27m%20Feeling%20Lucky>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. > ------------------------------------------------------------------------------------------------ > > > _______________________________________________ > aspectj-users mailing list > [email protected] > https://dev.eclipse.org/mailman/listinfo/aspectj-users > > -- mailto:[email protected] <[email protected]> skype:matthewadams12 googletalk:[email protected] http://matthewadams.me http://www.linkedin.com/in/matthewadams
_______________________________________________ aspectj-users mailing list [email protected] https://dev.eclipse.org/mailman/listinfo/aspectj-users
