David,

The problem you mention is definitely not trivial. However it is also quite 
common and there are some solutions.

The most general solution is to use a different category hierarchy for each 
"machine". When you write

   Category.getInstance(someName);

you are actually saying:

    defaultHierarchy.getInstance(someName);

where default hierarchy is the ..er.. the default hierarchy.

You can however specify the hierarchy where a category is attached:

   Category cat = hierarchy.getInstance(someName)

the returned category will be attached to hierarchy object making the call.

The difficulty of this solution is for the user to keep track of which 
category to use. This basically boils down to keeping track of application 
*context*. BTW, all major log4j components are geared to support 
non-default hierarchies. See the code in org.apache.log4j.net.SocketServer 
for an example of using multiple hierarchies.

In case your context is determined by a ThreadGroup or a Thread then you 
can use NDCs, but as you pointed out, this involves some work. In the next 
version of log4j, there will be support for automatic inheritance of 
contexts based on InheritabletThreadLocals. Unfortunately, This feature 
will only run under JDK 1.2. Cheers, Ceki





At 10:03 29.01.2001 -0800, you wrote:
>In order to run more app instances, e.g., HTTP load test clients, on a host,
>I often run multiple instances per machine.  For example, the app may
>instantiate 50 instances of a class, each in its own thread.
>
>I need to distinguish the 50 instances in the log4j output.
>
>- How can each app instance (w/i same JVM) go to a different appender, e.g.,
>file?  Does than a Category object for each of the 50 instances?
>
>- Assume each of the 50 app instances spawns several threads, e.g., worker
>threads.  In order for each app instance's threads to log to the appender
>for that app instance, would the Category objects have to be passed (CTOR or
>setter) to each associated thread?
>
>- Instead of an appender per app instance, NDC could be used.  But, all
>threads associated with an app instance's main thread would have to inherit
>NDC stack from spawning thread?
>
>Thank you.
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]

----
Ceki Gülcü - Independent IT Consultant

av. de Rumine 5            Tel: ++41 21 351 23 15
CH-1005 Lausanne        e-mail: [EMAIL PROTECTED]  or
Switzerland                     [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to