background preloader

Logging

Facebook Twitter

Logging Method Entry/Exit with Spring/AspectJ. The purpose of this blog entry is to show an extremely simple of example of "logging" entry into and exit from methods using the Spring Framework and AspectJ.

Logging Method Entry/Exit with Spring/AspectJ

The example is so simple that I won't actually use log4j or java.util.logging for the actual logging, although they could be easily added. The first code listing shows the XML file for the Spring context. Implement crosscutting concerns using Spring 2.0 AOP. Most developers will acknowledge how implementing crosscutting concerns such as logging, auditing, security and transactionality can adversely affect business logic implementation.

Implement crosscutting concerns using Spring 2.0 AOP

Such concerns "seem" to increase the complexity of existing business logic, at times making it difficult if not impossible to clearly distinguish business logic from the crosscutting concern implementation. I had been hearing about aspect-oriented programming (AOP) being a solution for implementing crosscutting concerns. But having read through early AOP tools documentation, I was dissuaded from using AOP in my projects' recommendations, primarily because of a concern that average developers might not "get" AOP concepts, and the overall ability to debug applications, and maintain them, might be restricted to those few who understood AOP.

Implement Logging as an Aspect Using Spring's AOP Framework. Bject-oriented programming (OOP) brought about the concept of encapsulation, inheritance, and polymorphism in order to create a hierarchy of objects that models a common set of behaviors.

Implement Logging as an Aspect Using Spring's AOP Framework

So, a particular set of objects is modeled to depict a particular pattern of behavior. But OOP does not explain how to handle a common behavior that extends across unrelated objects.