[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] System.out.prinltn and advicing

Hi,

You can match calls to PrintWriter.println(), and then test whether
the target of these calls is one of the instances in which you are
interested, using the "if" pointcut at runtime. This seems to work:

    pointcut sysout(PrintStream p, Object obj) :
                                        call(void PrintStream.println(..))
                                        && args(obj)
                                        && target(p)
                                        && if(p == System.out || p==System.err)
                                        && !within(SysOutLoggAspect);

Regards,

Cristiano


On 10/1/07, hermod.opstvedt@xxxxxxxxx <hermod.opstvedt@xxxxxxxxx> wrote:
>
>
> Hi
>
> Albeit no - It says it advises it, but when I run the tests, it never enters
> the around advice
>
> Hermod
>
>
> -----Original Message-----
> From: aspectj-users-bounces@xxxxxxxxxxx
> [mailto:aspectj-users-bounces@xxxxxxxxxxx] On Behalf Of
> hermod.opstvedt@xxxxxxxxx
> Sent: Monday, October 01, 2007 2:35 PM
> To: aspectj-users@xxxxxxxxxxx
> Subject: RE: [aspectj-users] System.out.prinltn and advicing
>
>
> Hi
>
> I solved it :)
>
>
>
> pointcut systemOut() : get(* System.out);
>
> pointcut systemErr() : get(* System.err);
>
> pointcut sysout() : call(void *.println(..)) && !within(SysOutLoggAspect) &&
> (cflow(systemOut()) || cflow(systemErr()));
>
> This seems to do the trick.
>
> Hermod
>
>
> -----Original Message-----
> From: aspectj-users-bounces@xxxxxxxxxxx
> [mailto:aspectj-users-bounces@xxxxxxxxxxx] On Behalf Of
> hermod.opstvedt@xxxxxxxxx
> Sent: Monday, October 01, 2007 2:12 PM
> To: aspectj-users@xxxxxxxxxxx
> Subject: [aspectj-users] System.out.prinltn and advicing
>
>
>
> Hi
>
> I am trying to write an advice that traps calls to System.out.println and
> System.err.println.
>
> If I write the advice as follows:
>
> public aspect SysOutLoggAspect {
>
>         private final Logger LOGGER =
> Logger.getLogger(SysOutLoggAspect.class);
>
>         pointcut sysout() : (call(void System.out.println(..)) || call(void
> System.err.println(..)) ) && !within(SysOutLoggAspect);
>
>         void around(Object obj) : sysout() && args(obj) {
>                 Level level = LOGGER.getEffectiveLevel();
>
> LOGGER.log(thisJoinPoint.getSignature().getDeclaringTypeName(),
> level,
>                                 obj, null);
>         }
> }
>
> It does not apply the advice, and issues a warning (no match for this type
> name: System.out [Xlint:invalidAbsoluteTypeName])  about it
> in Eclipse (AJDT). If I however rewrite the pointcut to:
>
>         pointcut sysout() : call(void *.println(..)) &&
> !within(SysOutLoggAspect);
>
> It does apply the advice, but I have no garantee that the method resides
> with System.out or System.err
>
> What is the best way to solve this?
>
> Hermod * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
> * * *
>
> This email with attachments is solely for the use of the individual or
> entity to whom it is addressed. Please also be aware that the DnB NOR Group
> cannot accept any payment orders or other legally binding correspondence
> with
> customers as a part of an email.
>
> This email message has been virus checked by the anti virus programs used
> in the DnB NOR Group.
>
> * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
>
> * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
>
> This email with attachments is solely for the use of the individual or
> entity to whom it is addressed. Please also be aware that the DnB NOR Group
> cannot accept any payment orders or other legally binding correspondence
> with
> customers as a part of an email.
>
> This email message has been virus checked by the anti virus programs used
> in the DnB NOR Group.
>
> * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
>
> * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
>
> This email with attachments is solely for the use of the individual or
> entity to whom it is addressed. Please also be aware that the DnB NOR Group
> cannot accept any payment orders or other legally binding correspondence
> with
> customers as a part of an email.
>
> This email message has been virus checked by the anti virus programs used
> in the DnB NOR Group.
>
> * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
>
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
>