Inherit appenders from calling instance in log4j or logback

Posted by Lord.Quackstar on Stack Overflow See other posts from Stack Overflow or by Lord.Quackstar
Published on 2010-05-16T19:00:48Z Indexed on 2010/05/16 19:40 UTC
Read the original article Hit count: 226

Filed under:
|
|
|

In my program I have 2 separate streams of logging events (calling them streams for simplicity, in reality its 2 appenders). Stream1 contains client logging and Stream2 contains control logging. Now this might seem easy, except that certain classes can be both in the client logging and server logging, depending on the situation. Complicating this further is the fact that a command that a client wants takes place in 2 separate threads (one being fetched randomly from a thread pool), so any kind of tracking with MDC or NDC isn't possible.

What would really simplify this is if the logger could inherit the appenders from the calling instance. That way I can setup 2 appenders for 2 loggers and be done. However I have no idea how to do it cleanly or easily. Can anyone offer any advice on how to do so?

Note: If something needs to be passed around, I do have a event bean that gets passed to everything in the chain that can be used if necessary.

© Stack Overflow or respective owner

Related posts about log4j

Related posts about logback