[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
RE: [aspectj-users] general tracing aspect
|
Your reply was most welcome! thanks :)
The solution you provided solves the problem of the class name to use in
advice but doesn't comply with my whish to have a single Logger instance per
class. This way every class will be logging to the same logger (the defined
one). What I would need would be a way to create a static logger instance
per-class using a type patern instead of a specific Type or a way to specify
that the logging is to take place in the logger variable that each class
already has.
Thanks again.
Nuno
-----Original Message-----
From: Gilles DODINET [mailto:rhill@xxxxxxxxxx]
Sent: Wednesday, April 23, 2003 1:20 PM
To: Nuno Oliveira
Subject: Re: [aspectj-users] general tracing aspect
what about something like
interface Loggable {}
declare parent : my.package.* implements Loggable;
//init logger as soon as possible (<init> ? <clinit> ?)
private Logger Loggable.anotherLogger;
pointcut method(Loggable o) :
within(Loggable+)
&& execution(* *(..))
&& this(o);
before(Loggable o): method(o)
{
o.anotherLogger.enter(
thisJoinPointStaticPart.getSignature().getName() ,
thisJoinPoint.getArgs());
}
i have not tested it, tho i think that it should work, with quite little
modifications. please provide me with some feedbacks :)
-- gd
> Message du 23/04/03 12:40
> De : Nuno Oliveira <noliveira@xxxxxx>
> A : aspectj-users@xxxxxxxxxxx
> Copie à :
> Objet : [aspectj-users] general tracing aspect
> Hello all,
>
> I have a bunch of classes each with its own static instance of a log4j
> logger. This instances all have the same name 'logger'. I want to add
> enter-leave tracing to each of the methods of all classes but would be
> interested in making this with a single aspect. However I'm having trouble
> with the sintax to refer to the logger in my advice, without using the
class
> name -which would defeat the purpose. I cannot use type patterns in
advice,
> rigth ? Can anyone provide any hints ? Using aspectJ, a sintatically wrong
> expression of my needs would be:
>
> package my.package;
>
> privileged aspect TraceEnterLeave
> {
> pointcut method(): within(my.package..*) && execution(* *(..));
>
> before(): method()
> {
>
>
(my.package..*).logger.enter(thisJoinPointStaticPart.getSignature().getName(
> ) ,
> thisJoinPoint.getArgs());
> }
>
> after() returning(Object o): method()
> {
>
>
(my.package..*).logger.leave(thisJoinPointStaticPart.getSignature().getName(
> ), o);
> }
> }
>
> A related question would be how to migrate the static logger declaration
in
> each class to that tracing aspect ? Could I use a type pattern to get the
> class name to instatiate each logger ?
>
> Thanks in advance.
>
> Nuno
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> http://dev.eclipse.org/mailman/listinfo/aspectj-users
>