

![]() | Start a set with this search |
![]() | Include this search in one of my sets |
![]() | Exclude this search from one of my sets |
![]() | Permalink to these results Paste this link in email or IM: |
| Atom feed for tracking future search results Paste this URL into your reader: |
13 messages in org.apache.logging.log4j-userRe: Log4j category for a thread| From | Sent On | Attachments |
|---|---|---|
| Tony Thompson | Jun 7, 2004 8:30 pm | |
| Paul Smith | Jun 7, 2004 8:43 pm | |
| Tony Thompson | Jun 8, 2004 6:11 am | |
| Ceki Gülcü | Jun 8, 2004 7:20 am | |
| Tony Thompson | Jun 8, 2004 8:00 am | |
| Ceki Gülcü | Jun 8, 2004 8:36 am | |
| Tony Thompson | Jun 8, 2004 9:06 am | |
| Paul Smith | Jun 8, 2004 3:21 pm | |
| Larry Young | Jun 8, 2004 4:09 pm | |
| Tony Thompson | Jun 8, 2004 5:31 pm | |
| Paul Smith | Jun 8, 2004 5:57 pm | |
| Sullivan, Sean C - MWT | Jun 8, 2004 6:04 pm | |
| Tony Thompson | Jun 8, 2004 8:07 pm |

![]() | Permalink for this message Paste this link in email or IM: |
![]() | Permalink for this thread Paste this link in email or IM: |
| Atom feed for this thread Paste this URL into your reader: |
| Subject: | Re: Log4j category for a thread | Actions... |
|---|---|---|
| From: | Tony Thompson (tony...@stone-ware.com) | |
| Date: | Jun 8, 2004 6:11:17 am | |
| List: | org.apache.logging.log4j-user | |
That is not really what I want. Let me expand my example a bit:
void methodA() { Logger logger = LogManager.getLogger( "methodA" ); utilityMethod( ... ); ... }
void methodB() { Logger logger = LogManager.getLogger( "methodB" ); utilityMethod( ... ); ... }
void utilityMethod() { // Which logger do I use? }
The NDC only gives me a way to put context sensitive information in the logging statements. What I want is a way to get a Logger based on some type of logging context. In my example, I want fine grained control of my logging categories but, utilityMethod() may be called from different places. Here is what I would like to see:
void methodA() { Logger logger = LogManager.pushLoggingContext( "methodA" ); utilityMethod( ... ); ... LogManager.popLoggingContext(); }
void methodB() { Logger logger = LogManager.pushLoggingContext( "methodB" ); utilityMethod( ... ); ... LogManager.popLoggingContext(); }
void utilityMethod() { // Use the current logger. Logger logger = LogManager.getLoggingContext(); }
This, of course, could go on further too. utilityMethod() could change the current Logger before it calls some other method, etc.
Make sense? Tony
psm...@apache.org 06/07/04 10:43PM >>>
What I think you want to use either the Nested Diagnostic Context (NDC) or the Mapped Diagnostic Context that is part of log4j and then have your appenders output them.
The NDC is a stack that you can push things on as your code goes down the call stack. The MDC is useful as a ThreadLocal map that is often used to track such things as the User/IP etc of the user making the current request.
Probably best to see this JavaDoc:
MDC: http://logging.apache.org/log4j/docs/api/org/apache/log4j/MDC.html
NDC: http://logging.apache.org/log4j/docs/api/org/apache/log4j/NDC.html
cheers,
Paul Smith
On Mon, 7 Jun 2004, Tony Thompson wrote:
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. Tony
---------------------------------------------------------------------
To unsubscribe, e-mail: log4...@logging.apache.org For additional commands, e-mail: log4...@logging.apache.org
--------------------------------------------------------------------- To unsubscribe, e-mail: log4...@logging.apache.org For additional commands, e-mail: log4...@logging.apache.org
------------------------------------------------------------ Mail was checked for spam by the Freeware Edition of No Spam Today! The Freeware Edition is free for personal and non-commercial use. You can remove this notice by purchasing a full license! To order or to find out more please visit: http://www.no-spam-today.com







