Announcement Announcement Module
No announcement yet.
Demystify: Implement logging with AOP Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Demystify: Implement logging with AOP

    Hello out there,

    being not that long introduced to Spring (6 month) i chose to use Spring in a small internal project to get familiar with it. Been using a lot of features of it quite successfull. After i have even configured some simple transaction management with AOP support of spring, i also thought I could use AOP to implement logging and thus keeping technical stuff out of my business code.

    As logging is one of the most presented examples for AOP implementation I thought this wouldn't be that tough, but I had to realize, that not one of the given acticles I read about logging with AOP (with Spring) implemented logging as i understand logging. As those examples mostly are satisfied with logging "Method entered", "Method exit", "Exception thrown" this is actuall not more than TRACING, isn't it?

    What I need to log if my method creates two folders in the filesystem, executes another method and deletes one of the created folders afterwards, is if the folders were created or/and deleted successfully. nt'Of course I could refactor those methods into smaller private methods, and let those be intercepted again but this would end up in two-line methods where AOP dictates my inner class structure.

    So to my mind Logging (respectively Tracing) with AOP is not possible, as I still have to instantiate logger classes and scatter all the logging outputs through my code.

    Don't get me wrong - I don't wanna criticise the implementation or the missing feature, as I understand that pointcuts can only be placed at method calls, returns or exceptions. I just want to discuss, if there is another fata morgana being placed or if I am too nearsighted.

    Any comments welcome,


  • #2
    That is exactly the view I currently hold and mentioned in a previous post. Granted I am an AOP newbie, just read the book "aspectj in action" and various articles and even did some aop (or gradually using more).

    But, since an advice can gain access to its context perhaps there is a way to make this 'tracing' more like logging. For example, at a joinpoint, an aspect can inspect the object to see if it has a particular method that can query the state of the object and thereby a more appropiate logging output is produced (not the same as it's toString). There is a name for this pattern that I can't recall, collecting parameter? Still seems kludgy.

    Anyway, since the term logging is used for many different things, like web server access logs, its not really an incorrect use of the term in AOP. Perhaps, AOP allows declaritive logging, whereas what we are most familiar with is programmatic logging.