Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] using static fields in an advice

Hi Alexander,

all I would like to know if it is possible to user a calls field (static field in an advice and how does it look like.

Could be that I did not understand something. But I thought when using AspectJ to compile time the enriched program could be run without aspectj-library under certain circumstances.

But this is just another addon-question. Using a static field in an advice could be worthy in also not logging-circumstances, couldn’t it?

 

>Please explain your problem more clearly. Is your intention to do some logging from within aspects and some in your core code, both using the same Logger instance? And is your logger >identified by something else than the class name?

Yes I am using the same very same logger in bothin the advice and in the particular class.

And yes as well:  The logger is always identified in a static field like this

Static Logger logger = Logger.get(MyClass.class);

 

I first thought  I could do this with parameters, but I always got compile-errors.

The code below works, but why not using a field that is already there?

 

 

Von: aspectj-users-bounces@xxxxxxxxxxx [mailto:aspectj-users-bounces@xxxxxxxxxxx] Im Auftrag von Alexander Kriegisch
Gesendet: Dienstag, 12. Februar 2013 16:24
An: aspectj-users@xxxxxxxxxxx
Betreff: Re: [aspectj-users] using static fields in an advice

 

Hi Malte.

 

So you want to use AspectJ for logging, but you do not want to depend on the AspectJ runtime? This is kind of a contradiction, assuming that logging is a production aspect, not just a development aspect. ;-)

 

 

Alexander Kriegisch


Am 12.02.2013 um 16:11 schrieb "Kempff, Malte" <Malte.Kempff@xxxxxxxxxxxxx>:

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. ------------------------------------------------------------------------------------------------

_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users

------------------------------------------------------------------------------------------------ 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. ------------------------------------------------------------------------------------------------

Back to the top