Results 1 to 3 of 3

Thread: Different strings in logging messages

  1. #1
    Join Date
    Aug 2006
    Posts
    2

    Default Different strings in logging messages

    Hi,

    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:
    Code:
    log.debug("Beginning method: " + method.getName());
    -OR-
    log.error("Exception in method: " + method.getName() + 
                "Exception is: " + ex.getMessage());
    Is there any way to customize your logging messages with specific strings?

    Thanks,
    Larry

  2. #2
    Join Date
    Jun 2006
    Location
    SF Bay Area, California
    Posts
    524

    Default 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.

    -Ramnivas
    Ramnivas Laddad (Follow me on Twitter)
    AspectJ in Action: Enterprise AOP with Spring Applications (2nd edition). Now available!

  3. #3
    Join Date
    Aug 2006
    Posts
    2

    Default Thanks

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •