[logback-user] Question about MDC in servlet init() method
stefan at meinemullemaus.de
Mon Mar 3 09:37:51 CET 2008
Thanks for your clarification.
In my case the applicationName is nott related to lockback because I
do not use logback. But I use the MDC class with my own logger. MDC
can be very handy if man understand correctly how it works and where
it does not.
Message from Ceki Gulcu
> Hello Stephan,
> Values placed in the MDC are valid for the current thread only. When
> a servlet
> responds to an HTTP request, it may or may not be running under the
> same thread
> that invoked its init() method.
> You have several options. You can set MDC at the beginning of your
> service method. If you have multiple servlets, you can set the MDC
> from a
> servlet *filter* for a group of servlets before they get invoked.
> As for setting the applicationName for your web-application, I think
> this is
> such as general requirement that logback should support this feature
> out of the
> box. I am creating a bug report to remind myself.
> I hope this helps,
> Stefan Frings wrote:
>> Lets assume I call MDC.put("applicationName","whatever") in the
>> servlet init() method. Can I read this later in the service()
>> I'm asking because some weeks ago I noticed that this did not
>> I assumed that the threads running service() are not childrens of
>> the thread that runs init().
>> However, I tried this again today, and this time it worked fine. I
>> was not able to reproduce the problem.
>> But before I do such things now in real web applications, I like
>> be sure if thats Ok.
>> Can I set MDC variables in init() and read them in service()
>> or does this work only randomly or under special conditions?
> Ceki Gülcü
> QOS.ch is looking to hire talented developers in Switzerland. If
> interested, please contact c e k i @ q o s . c h
> Logback-user mailing list
> Logback-user at qos.ch
More information about the Logback-user