Howdy,

>I'll take a look into the Log4J.MDC - don't you think it would make
sense
>to provide guidelines on how to log debugmessages and exceptions in
>servlet/jsp-apps (like the App Dev. Guide of Craig)? or is there
already
>something at the log4j site you know of?

There isn't something explicit: if you write something I'll put it on
the site ;)  It's fairly simple, though.  For example, if you want all
session and request attributes in the MDC, from a servlet, you would do:

// Populate MDC with request attributes
MDC.getContext().put(request.getParameterMap());
// Populate MDC with session attributes
Enumeration sAttributes = session.getAttributeNames();
String name;
while(sAttributes.hasMoreElements()) {
   name = sAttributes.nextElement();
   MDC.put(name, session.getAttribute(name));
}
// Log
logger.info("something");
// Clear MDC to save memory
MDC.getContext().clear();

There's a gotcha here, though.  You would need to declare those keys in
the MDC you want output to your log file by using %X{KeyName} in your
layout declaration.  Perhaps a modification to PatternLayout is needed
to output the entire MDC.  But anyways, that's to be discussed on the
log4j-user list if you're interested.

Yoav Shapira




This e-mail, including any attachments, is a confidential business communication, and 
may contain information that is confidential, proprietary and/or privileged.  This 
e-mail is intended only for the individual(s) to whom it is addressed, and may not be 
saved, copied, printed, disclosed or used by anyone else.  If you are not the(an) 
intended recipient, please immediately delete this e-mail from your computer system 
and notify the sender.  Thank you.


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

Reply via email to