Announcement Announcement Module
No announcement yet.
Different strings in logging messages Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Different strings in logging messages


    I am new to AOP and love the concept! I am in the process of removing my embedded logging messages and replacing them with aspects.

    Here's my question: Many of my logging messages consist of specific strings. Sometimes the message consists of just a string (e.g. "Null prodcut ID") and sometimes it's a string coupled with runtime information (e.g. "Search returned more than one match for " + customerID).

    In all of the Spring/AOP/logging examples I have seen there is just a simple generic output string that can be applied to all cases. For example:
    log.debug("Beginning method: " + method.getName());
    log.error("Exception in method: " + method.getName() + 
                "Exception is: " + ex.getMessage());
    Is there any way to customize your logging messages with specific strings?


  • #2
    Use different pointcuts or direct calls

    You may get what you need by using separate pointcuts and advice for each kind of situation.

    However, from what you describe, it sounds like you need a custom message for each kind of situation. Unless those situations occur in multiple places, aspects may not offer the best solution. Generally, in a typical application, you use aspects to perform crosscutting form of logging (entering/exiting methods, handing exceptions, calling specific methods, changing the state of objects of certain kinds, etc.). For business-specific logging, the direct call is often the best solution.



    • #3

      Thanks a lot, Ramnivas. That's what I thought, but I wasn't sure because I'm just starting out and I figured there was a good chance I was missing something. (After all, there is quite a lot! :-)

      Again, thanks for taking the time to answer my question.

      -- Larry