Audit logging is quite important in any application. I've seen many approaches. Some were quite heavy, some were elegant. Using AOP to achieve transparency, JMS to achieve asynchronousity, other fancy stuff.
However, I am more and more inclined to simply use logging framework and do it explicitely in the code separately from normal logging.
Something like:
public class MyClass {
public static final Logger log = Logger.getLogger(MyClass.class);
public static final Logger audit = Logger.getLogger(Audit.class);
public void myMethod(String parameter) {
audit.info("myMethod");
...
log.debug("Debug1");
}
}
Maybe wrapping this call completely in Audit class with a static log method is even better. Or just providing a wrapper around logging framework with a special audit method.
Just thoughts out loud so far.
Mostly based on several ideas:
Gathering everything like a blindly instrumented code would do often proves useless. Though I have to admit that not requiring developer to type these lines seems very attractive.
A logging framework has already been optimized in terms of performance. Multiple plugins are available to let it spit the messages to SMNP, JMS, database. It has means to roll the logs, there are tools to filter them.