Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [aspectj-users] around() Problem

Someone once posted some code on how to do this which I shamelessly copied
and implemented -- thanks to whomever that was.

Here is an example:

/*----------- Pointcuts --------------------*/
  // There may be some methods, like "main" methods,
  // that you want to ignore.
  protected abstract pointcut ignorable();

  // catch PrintStream.print messages
  pointcut sysIO(PrintStream out, Object message):
    call(void PrintStream.print*(..)) &&
    target(out) && args(message) && !ignorable();

  // its unlikely but possible that someone will call
  // System.out.println() with no arguments -- let's ignore that
  pointcut sysIONL(PrintStream out):
    call(void PrintStream.println()) && 
    target(out) && !ignorable();

  // Catch Exception Stack Trace Prints
  pointcut stackTrace(Throwable t):
    call(void Throwable.printStackTrace()) && 
    target(t) && !ignorable();

/*----------- Advice --------------------------*/
  void around(PrintStream out, Object message): sysIO(out, message) {
    if((out == System.out) || (out == System.err))
      logger.info(message);
    else
      proceed(out, message);
  }

  void around(PrintStream out): sysIONL(out) {
    if (out == System.out || out == System.err)
      ; // do nothing
    else
      proceed(out);
  }

  void around(Throwable t): stackTrace(t) {
    logger.warn("Caught Stack Trace Print from code", t);
  }


-----Original Message-----
From: Michael Dempfle [mailto:mdempfle@xxxxxxxxxx]
Sent: Monday, July 28, 2003 11:40 AM
To: aspectj-users@xxxxxxxxxxx
Subject: [aspectj-users] around() Problem


Hi,

I've tried now some time to catch all System.outs in my code and can't 
make it.

In the end I want to catch alle the outputs in an existing application 
and want to write it
to a logfile.

But for testing I simply want to catch all System.outs with this code:

public aspect SystemOut {
    pointcut pprint(String str) :
        call(void System.out.println(*)) && target(str) ;

    void around(String str) : pprint(str) {
        System.out.println("Catched in " + thisJoinPoint + ": " + str);
        proceed(str);
    }
}

And I always get the message: no match for this type name
But I extra put in this line of code to test: System.out.println("Test");

What I am doing wrong?
Is there a problem because System.out.println exists for a lot of objects?
I want to catch them independent if it's called with an int or a String 
or ....

Thanks,
Michael





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


Back to the top