What I have created is a simple custom logging annotation which when applied to a method on a spring managed bean will log out at the given level and print the method name and args invoked with.
Ive created a sample/demonstration project over on my GitHub which can found here. To see the loogin simple run the main method inside the demonstration project form GitHub.
Here is a usage demonstration of how an application can utilise the Logging annotation.
Simply annotate your method and when it gets invoke you will having logging such as this.
13:27:48.560 [main] DEBUG c.morgan.design.demo.LoggingExample - Method Invocation=[logMe] - Args=[] 13:27:48.561 [main] INFO c.morgan.design.demo.LoggingExample - Method Invocation=[logMeInfoWithMethodArgs] - Args=[abcdefg, 1234] 13:27:48.561 [main] WARN c.morgan.design.demo.LoggingExample - Method Invocation=[logMeWarningWithMethodArgs] - Args=[abcdefg, 1234, true] 13:27:48.573 [main] DEBUG c.morgan.design.demo.LoggingExample - Method Invocation=[logMeDebugWithMethodArgs] - Args=[abcdefg, 1234, false, 0.2]
This is only a sample project, If this was to be used in a more production ready application I'm pretty sure I would pick a better name. :)
This is how the demonstration Logging Aspect looks:
I've chosen to take an annotation based approach but this could also be done using XML configuration.
Enhancements to make would be:
* Instead of having three different methods for the various logging level, have only one and retrieve the annotation from the method and determine its logging level from the annotation value.
* At the moment this only supports log-back and log4j, this could be made more abstract and determine the logging libraries for each application.
* Make it in to a library project in which you could simple include the library and configure it. i.e. only log for particular methods, packages etc.
* Allow for custom logging pattern configuration.
Anyway, its a small simple sample of the power of AspectJ, all comments welcome as usual.