[logback-dev] MDC good concept but...Thread-Support

Ceki Gulcu listid at qos.ch
Wed Aug 29 23:18:14 CEST 2007


Hi Peter,

Java offers the notion of "inheritable thread local" data which would take 
conveying MDC data to child threads. There is even a bug report on this issue:

   http://bugzilla.qos.ch/show_bug.cgi?id=64

Would the solution described in bug 64 (above) work for you?

Cheers,

peter huber wrote:
>   Hi LogBack-Team,
> 
> just want to tell you that MDC lacks thread support.
> But I'm quite sure that you know that. As soon as you
> "leave" a thread the MDC conext (ThreadLocal) will be
> lost. 
> I had implemented something similar to MDC a while ago
> and I accompanied my impl with a
> ContextPreservingRunnable after a while. 
> 
> Works like this
> 
> CTOR (Source Thread):
> ContextPreservingRunnable(Runnable inSubject) {
>    myMemento = MDC.getMemento();
>    mySubject = inSubject;
> }
> 
> RUN-Method (Target Thread):
> void run() {
>    MDC.setMemento(myMemento);
>    mySubject.run();
>    MDC.clear();
> }
> 
> Even though it works for me, it's rather bad that you
> have to wrap all Runnables and Callables respectively.
> 
> Maybe a ExecutorFacade might server the purpose?
> 
> BTW: Does MDC include support for a Subjects
> Principals (JAAS)...Please forgive me my showing off
> at dev list;-)
> 
> 
> 
> 
>        __________________________________ 
> Yahoo! Clever - Der einfachste Weg, Fragen zu stellen und Wissenswertes mit Anderen zu teilen. www.yahoo.de/clever
> 
> _______________________________________________
> logback-dev mailing list
> logback-dev at qos.ch
> http://qos.ch/mailman/listinfo/logback-dev

-- 
Ceki Gülcü
Logback: The reliable, generic, fast and flexible logging framework for Java.
http://logback.qos.ch



More information about the logback-dev mailing list