13 messages in org.apache.logging.log4j-userRe: Log4j category for a thread
FromSent OnAttachments
Tony ThompsonJun 7, 2004 8:30 pm 
Paul SmithJun 7, 2004 8:43 pm 
Tony ThompsonJun 8, 2004 6:11 am 
Ceki GülcüJun 8, 2004 7:20 am 
Tony ThompsonJun 8, 2004 8:00 am 
Ceki GülcüJun 8, 2004 8:36 am 
Tony ThompsonJun 8, 2004 9:06 am 
Paul SmithJun 8, 2004 3:21 pm 
Larry YoungJun 8, 2004 4:09 pm 
Tony ThompsonJun 8, 2004 5:31 pm 
Paul SmithJun 8, 2004 5:57 pm 
Sullivan, Sean C - MWTJun 8, 2004 6:04 pm 
Tony ThompsonJun 8, 2004 8:07 pm 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: Log4j category for a threadActions...
From:Paul Smith (psm@apache.org)
Date:Jun 8, 2004 3:21:02 pm
List:org.apache.logging.log4j-user

I would suggest then simply setting up a ThreadLocal Logger then, configured at the start of your request, that all the participants expect to be there.

On Tue, 8 Jun 2004, Tony Thompson wrote:

Pardon my asking but what is wrong with:

void getUser() { Logger logger = LogManager.getLogger( "org.widgets.getUser" ); }

or just

void getUser() { Logger logger = LogManager.getLogger( "org.widgets" ); }

Why should the logging in getUser() care if it has been called by login() or by logout()?

Please bear with me, I am trying to understand the use case.

No problem.

I don't really want getUser() to have its own logging category. What I am concerned about is the end user experience. If I am the end user and I want to see DEBUG for the login process, I shouldn't have to set DEBUG levels on more than one category. I should set DEBUG for "org.widgets.login" and see all of the debug available for the login process. Plus, getUser() would display DEBUG messages every time logout() is called which is not what I wanted either.

Now, as the server developer, I could implement getUser() like this:

void getUser( Logger logger ) { }

and just pass the logger in every time I call it. That would accomplish the same thing. But, I don't really want to mess with all of the code that calls getUser() and pass in a Logger.

So, to me, the cleanest solution would be to set a Logger for the current thread. Then getUser() can just grab the "current" logger and use that. It doesn't care because it is only part of a larger process anyway. This is an implementation detail but, you would also need a default category (maybe the root logger) to log messages to in case the caller hasn't set a logger context. Either way, getUser() relies on someone else to tell it what its logger should be.