Howdy,

>im just getting started with using log4j and I am trying to use it
within
>my
>servlet.  From reading the archives it appears i need to be using the
MDC
>class, but i am a little confused as to how it works and how it is used
in

First of all, the MDC is entirely optional.  Many people never use it.
It comes into play if you think you might have multiple logging messages
that you want to distinguish based on some field, e.g. the user's IP
address if you have many users concurrently using a servlet.

>code.  is it as easy to implement like in the following psuedo-code or
is
>there more to it?  how do you use it in your helper classes outside
your
>servlet?  It just seems im missing something.  can someone shed some
like?

Your pseudo code is just fine, and this illustrates a good use of the
MDC.  The MDC is not technically tied to servlets, so you can use it
just the same from any other java class.  For example if you have
multiple applications, i.e. multiple JVMs, logging to the same java file
(this is just an example, not necessarily a good idea), you might add
the executing user's name to the MDC by doing MDC.put("username",
System.getProperty("user.name")).

But as I said, MDC is entirely optional.  Don't use it unless you have
to ;)

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