[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Add per-class static log4j instance using AspectJ.

Look at 'pertypewithin' as an aspect instantiation model.

On 08/08/07, Davy Toch <Davy.Toch@xxxxxxxxxxxx> wrote:
> Hi,
>
> I have the following class :
>
>   public class Bar {
>     public void test() {
>     }
>   }
>
> I want to use AspectJ AOP to add a private static log4j instance that is
> initialized with the current classname as category, so subsequent calls
> to the logger will log under this category.
>
> So AspectJ should generate something like the following in the bytecode:
>
>   public class Bar {
>
>     private static org.apache.log4j.Logger logger = null;
>
>     static {
>       logger = org.apache.log4j.Logger.getLogger(Bar.class.getName());
>     }
>
>     public void test() {
>       logger.trace("+test");
>     }
>   }
>
> Is this possible?
>
> Also I noticed that if I want to add a member 'logger' to my class
> 'Bar' using AspectJ, I have to add the following to the aspect:
>
> public aspect MyTracingAspect {
>
>   private static org.apache.log4j.Logger Bar.logger = null;
>
>   ...
> }
>
> However instead of Bar.logger, I want to put something like (*).logger,
> so the logger member is added to all types on which the aspect is applied.
>
> Best regards,
> Davy Toch
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>