On Oct 19, 2007, at 4:12 AM, Michael wrote:
Dear sir,
Recently I was try with the log4j to use it to record my system out
messages, however it seems that when I want to have 2 thread within
the same JVM where each of them having their own log files is not
possible. Because the Logger object is singleton.
Is there any way that I can have init 2 different instance of
Logger (with different configuration of file to be write to) on
each thread and each their own log files ??
Thanks,
Logger is not singleton, there can be many instances of Logger.
However, only one logger in a hierarchy can gave a particular name.
Having multiple hierarchies (which would allow you to have multiple
instances of Logger with the same name) would require that you pass
the Logger or LoggerRepository as a parameter to all your methods or
use some other mechanism to access the appropriate repository for
your thread. A better approach is to have a single appender that
writes to multiple files depending on the thread making the logging
request.
There was a discussion on 16-Oct-2007 on log4j-user of an appender
that used thread local storage to accomplish that. Also, there was a
experimental effort to develop a MultifileAppender where file-per-
thread was one of several use-cases, but that effort languished
because of competing demands on my time and no others pitching in.
As mentioned in the recent thread on log4j-user, the topic has come
up repeatedly recently and I'd like to finish off the
MultifileAppender effort and put it into extras.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]