logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Aditya Prasad" <akpra...@gmail.com>
Subject Thread-specific appenders
Date Wed, 17 Oct 2007 03:40:41 GMT
Hi all,

I've written an appender that writes to different files based on the
caller's thread id, but I'm not sure I've done it the best way.
Here's my scenario:

I have a JUnit test driver that runs about 50 tests from a suite.
Because it takes too long to run them sequentially, and they're
independent, I am running them in parallel (one per thread).  I would
like their outputs to go to different files.  Since much of the
logging is being performed by third-party software (e.g., HttpClient),
I can't simply create a different logger for each test.

So I've created a ThreadLocalFileAppender, which (as its name
suggests) has a ThreadLocal instance that stores a FileAppender per
thread.  The file locations are determined by thread name.  It
implements the Appender interface, and the method implementations
simply grab the TL appender and delegate the calls.

Three questions:

1) Is there an existing class I should be using instead?

2) Should I not have implemented Appender directly?  I thought about
extending FileAppender so I could expose its interface, but
AppenderSkeleton has final methods that I probably want to override.

3) Can I not set properties (like the Layout) via log4j.properties if
I do this?  It doesn't seem to work.  (In fact, I can't find any good
documentation on how exactly log4j.properties performs its magic.  I
figured it was a simple IoC pattern, but it appears it's not).

Thanks!
Aditya

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Mime
View raw message