I have an AspectJ tracking procedure configured to enter and exit log mode using the following points:
public aspect Trace { pointcut anyMethodExecuted(): execution (* biz.ianw.lanchecker.*.*(..)) && !within(Trace) && !within( is(AnonymousType) ); pointcut anyConstructorExecuted(): execution (biz.ianw.lanchecker.*.new(..)) && !within(Trace);
In my sendEmail class, I have a method that calls the setDebugOut method to redirect debug output to a LogOutputStream:
final private static Logger log = LoggerFactory.getLogger(MailMail.class); ... LogOutputStream losStdOut = new LogOutputStream() { @Override protected void processLine(String line, int level) { log.debug(line); } }; public void sendPlainHtmlMessage(...) { Session session = javaMailSender.getSession(); PrintStream printStreamLOS = new PrintStream(losStdOut); session.setDebugOut(printStreamLOS); ...
This works great, except that the pointcut of the Trace class intercepts a call to the anonymous inner class, creating as output:
20:14:18.908 TRACE [biz.ianw.lanchecker.Trace] - Enters method: Logger biz.ianw.lanchecker.MailMail.access$0() 20:14:18.909 TRACE [biz.ianw.lanchecker.Trace] - Exits method: Logger biz.ianw.lanchecker.MailMail.access$0(). 20:14:18.909 TRACE [biz.ianw.lanchecker.Trace] - with return value: Logger[biz.ianw.lanchecker.MailMail] 20:14:18.909 DEBUG [biz.ianw.lanchecker.MailMail] - DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
I added a pretty wide
&& !within( is(AnonymousType) )
the condition for the pointcut, as shown above, but it had no effect. Actually, I have a real difficulty in finding (anonymous type), somewhere documented somewhere.
How can I write a pointcut that excludes this anonymous internal method, preferably without affecting others?
source share