RE: Logging / Exception handling framework within Tomcat

2004-02-06 Thread Shapira, Yoav

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]



RE: Logging / Exception handling framework within Tomcat

2004-02-06 Thread Johannes
hi yoav,

I've been showing up here some months ago, and now you're still on your 
job answering the many answers here. I'm impressed...

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?

thx alot
Johannes

RE: Logging / Exception handling framework within Tomcat

2004-02-06 Thread Shapira, Yoav

Howdy,
You need to read the log4j documentation: that framework is far from
basic, very complete, and meets all your requirements.

Log4j supports modifying properties at runtime.  You can write your own
code following instructions to do this, or you can use the log4j
sandbox's configuration servlet.

Log4j also supports adding contextual information to every log message.
There are several approaches possible here, but MDC
(org.apache.log4j.MDC) is probably what you want.

If you have further specific questions feel free to ask on the
log4j-user mailing list.

Yoav Shapira
Millennium ChemInformatics


>-Original Message-
>From: Johannes [mailto:[EMAIL PROTECTED]
>Sent: Friday, February 06, 2004 3:11 PM
>To: [EMAIL PROTECTED]
>Subject: Logging / Exception handling framework within Tomcat
>
>hi there,
>
>As of TC 4.x I know the following architecture exists for logging
within
>an application:
>
>From the very basic
>*) System.out.println, which goes to catalina.out / stdout.log
>*) e.printStackTrace(), which goes to catalina.out / stderr.log
>
>up to more advanced:
>*) using context.log() to write into the servlet context's log file
>*) using Log4J to redirect log output to files / jdbc interfaces
>
>However, in real life I found these approaches are very basic and not
>sufficient:
>*) If I want to debug, I usually want to debug complete transactions =
I
>want to know what was stored inside the request, where did it come
from,
>what was the content of the session, and what was the complete debug
>logging of the whole transaction (including all methods called / walked
>through).
>I wrote a small framework to handle such transaction debug logs
>completely. Is anybody else interested in this issue?
>
>*) If an exception arises, the stacktrace in catalina.out is a
nightmare
>to troubleshoot. To be productive in detecting runtime exceptions, one
>needs a complete transaction log to know exactly what happened.
>Complete transaction log means to me:
>- complete data of the HttpServletRequest
>- complete data of the HttpSession
>- everything that might identify the user (Cookies, RemoteAddress,
>Browser, ...)
>- complete stacktrace
>
>Additionally, I needed to turn on/off debugging during RUNTIME, which
>currently is not supported using Log4J (because it stores its data
inside
>properties files within the WAR file). I wrote a small Singleton to
>support turning logging ON/OFF during runtime.
>
>I'd appreciate if anybody else can share his thoughts on this topic.
Maybe
>Log4J/the JDK Logging API provides options that I don't know of yet.
>
>thx
>Johannes



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]