You could probably set a system property for each classloader if the
classloaders use parent-last behavior like the servlet spec defines.  So when
you configure log4j each time, your config file could reference file names
based  on a system property, making all of them unique....

log4j.appender.MYAPPENDER.File=${logdir}/myapp_${app_instance_name}.log

Of course this requires configuring log4j separately each time within each
parent-last classloader instance.  In that case, you could even point to
separate log4j config files to use rather than parameterizing one config file.

Or you could write a ContextClassLoaderSelector (a repository selector based on
classloader) and configure log4j per repository.  See info at....

http://www.qos.ch/logging/sc.jsp

There is actually a classloader-based selector example there written for
Log4j-1.2.x.  It won't work as written in Log4j-1.3 since the interface
changed.


Jake

Quoting Boris Klug <[EMAIL PROTECTED]>:

> Hi!
>
> We need to run the same Java program say 20 times. Only difference is the
> configuration of the program. For this, starting 20 jvms is very memory
> consuming so I wrote a Java program which can load other Java applicationwith
> a different classloader for each application) and execute the void main(...)
> in a own thread.
> This works fine, we can now run the 20 instances of our program in one jvm
> which saves a log of memory.
>
> The problem now is that all of the 20 programs do logging with log4j and all
> log to the same file because the package and class names are all the same.
>
> So my question is:
>
> 1) Can i set a different log4j configuration for a thread?
> 2) Is there another way to divide the 20 instances for logging?
>
> Thanks in advance!
>
>
> --
> Dipl. Inform. Boris Klug, control IT GmbH, Koblenz, Germany
> http://www.control.de/ - Fon: +49 261-92748-321 - Fax: -336
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>




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

Reply via email to