logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tony Thompson" <tony.thomp...@stone-ware.com>
Subject Log4j category for a thread
Date Tue, 08 Jun 2004 03:30:54 GMT
Is there any way currently to set a logging "context" for a thread?  For
example, if I have a utility method that I call from two other methods,
I don't want to create a new category just for that utility method.

void methodA() {
    utilityMethod( ... );

void methodB() {
    utilityMethod( ... );

When utilityMethod() is called from methodA(), I want it to use the
logging category established for methodA().  When it is called from
methodB(), I want it to use the category for methodB().

I would prefer not to pass in the Logger when I call utilityMethod()
because I want to do this in existing code and it would take a bunch of
extra work and be unnecessarily ugly.  What would be ideal would be to
have the LogManager keep a ThreadLocal with the current logging
"context" (probably a stack).  As methods get called, they can push a
new logging context onto the stack, if they wish or simply let the
current one be used for the current thread of execution.

If log4j can't do this for me, would it make sense for log4j to offer
this type of functionality?

Thanks for any help.

To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org

View raw message