On Thu, 2004-02-05 at 09:03, [EMAIL PROTECTED] wrote:
> I'm not sure if the memento will work. Here is our scenario:
> 
> We have a map of parameters that need to go into MDC that we want to
> print in the log as a block. So, lifecycle looks like this:
> 
> SharedContext.put("userId", "bob");
> ...
> SharedContext.put("transactionId", "123");
> ...
> logger.info("Something happened.");
> 
> Want log line to look like (this is simplified):
> 
> 04 Feb 13:39 INFO my.Class (transactionId=123,userId=bob]) - Something
> happened.
> 
> The main requirement that led me to not just put stuff directly in MDC
> is that I have an unconstrained list of keys (so can't have a layout
> like "transactionId=%X{transactionId},userId=%X{userId}"). Also, though
> I could get around this if I dug into PatternLayout a little, I want a
> custom "format" of the MDC portion...so in my case, I have a custom
> toString() method in the map that I add to MDC.
> 
> I can also envision a scenario where I might want to format different
> chunks differently, like: "codes:1,3,6,5,4 transactionId=5" where MDC
> looked like: codes=<list of some codes that are added to over time>
> transactionId=<simple value>

If I was in your shoes, I would log to XMLLayout, and then either
stylesheet it (bleagh) or use Chainsaw v2 to peruse/query it.  Lots of
nice MDC support in Chainsawv2...  

Your SharedContext class could quietly add the values to the MDC on it's
put call and quietly remove them on a SharedContext.remove(...) call (I
assume you have one of those).  That way any client code of your
SharedContext class doesn't even have to know about MDC.

Usually there are known MDC keys that you always know are going to be
there (userid, transactionId etc) and you could have another simple file
appender outputting these standard ones for just simple viewing (tail/vi
etc), but the real logging would be done in XML, which gives you a lot
more flexibility.

This would also take only about 120 seconds to configure/do, if I
understand thing correctly.

cheers,

Paul


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to