If you encapsulated all your logging in the aspect (and so didn't need to access it from outside the aspect), you could use a pertypewithin aspect which creates an aspect instance per woven class.
Any instance based state in your aspect is then effectively per-type.
public aspect LoggingAspect pertypewithin(org.foo..*) // per-type association
{ Logger logger;
after() : staticinitialization(*) { // run 1x after class-loading
logger = Logger.getLogger(
getWithinTypeName() // type associated with aspect instance
);
}
pointcut logged() : // what to log, e.g. public methods
execution(public * *(..)); // (pointcut could also be abstract
// and refined in sub-aspects)
before() : logged() {
logger.log(...); // logging action
}
}
>Is it really necessary if AspectJ used for compile time weaving and not used any of the classes or methods within the advices, to have the aspectj-library within your program?
I answered this in stackoverflow the other day. Yes, it is necessary. The small runtime not only contains stuff to support thisJoinPoint/etc but also internally used classes for handling pointcuts like cflow and exceptions like 'NoSuchAspectException' that may occur. It would be possibly to generate all this stuff during a build, leaving you no dependencies on an aspectj runtime but not enough people have requested it to justify the effort.
cheers,
Andy