On the Spring-based web app project I'm on now, the developers have written two logging statements into every function. One logging the entry into the function, the other logging the exit. The idea is to trace the execution path -- at least a function level.
Is there a way to accomplish this without littering the entire code base with these repetitive statements?
To be clear, we want to log all functions, not just public methods of Spring beans.
You can do this with Spring AOP.
Spring AOP will allow you to 'intercept' method calls and perform arbitrary code before and/or after the method call. You will also be able to examine parameters and return values of these methods.
To achieve the logging you are talking about, you would do something like this, likely using the around advice:
All of the Spring details about how to do this can be found in the documentation provided.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With