Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] How to exclude nested matching method executions?

I have improved my implementation.

Here is the abstract LoggerAspect:
============================================================
public abstract aspect LoggerAspect {
  public Logger ILoggable.getLogger() {
    return LoggerAspect.getLogger(this.getClass());
  }
  
  public static Logger getLogger(@SuppressWarnings("rawtypes") Class clazz)
{
    LoggerHolderAspect holder = LoggerHolderAspect.aspectOf(clazz);
    return holder.getLogger();
  }

  abstract pointcut loggedScope();
  abstract pointcut loggedMethods();
  
  private static Logger getLogger(JoinPoint.StaticPart jp) {
    return getLoggerHolder(jp).getLogger();
  }

  private static LoggerHolderAspect getLoggerHolder(JoinPoint.StaticPart jp)
{
    return
LoggerHolderAspect.aspectOf(jp.getSignature().getDeclaringType());
  }
  
  before(): staticinitialization(!LoggerAspect+) && loggedScope() {
    getLoggerHolder(thisJoinPointStaticPart).initLogger();
  }

  before(): loggedScope() && loggedMethods() {
    logBefore(getLogger(thisJoinPointStaticPart), thisJoinPoint);
  }

  after() returning (Object result): loggedScope() && loggedMethods() {
    logAfterReturning(getLogger(thisJoinPointStaticPart), thisJoinPoint,
result);
  }
  
  after() throwing (Exception e): loggedScope() && loggedMethods() {
    logAfterThrowing(getLogger(thisJoinPointStaticPart), thisJoinPoint, e);
  }

  protected void logBefore(Logger l, JoinPoint jp) { ... }
  protected void logAfterReturning(Logger l, JoinPoint jp, Object result) {
... }
  protected void logAfterThrowing(Logger l, JoinPoint jp, Exception e) { ...
}
}
============================================================

Here is a concrete extender - ResourceHandlerLoggerAspect:
============================================================
public aspect ResourceHandlerLoggerAspect extends LoggerAspect {
  declare @type : @Path * : @LogMe;
  declare parents: (@Path *) implements ILoggable;
  
  pointcut loggedScope() : within(@Path *);
  pointcut loggedMethods() : execution(@(GET || PUT || POST || DELETE)
public * *.*(..));
}
============================================================

I have a feeling that it should be easier now to deal with the repeating
exception logging, though it still escapes my understanding how to do it.


--
View this message in context: http://aspectj.2085585.n4.nabble.com/How-to-exclude-nested-matching-method-executions-tp4172075p4178500.html
Sent from the AspectJ - users mailing list archive at Nabble.com.


Back to the top