• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

MDC across context instead of thread

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey folks,

I've encountered a bit of a problem with using log4j's MDC class within applications in weblogic. It's not a bug at all it's just giving me grief.

Basically I've setup ApplicationLifecycleListener on my ear app and on all web apps within weblogic. They're there to catch startup events so that I can slot the application name into the MDC in order to be able to retrieve it when an exception occurs.
Web :-
MDC.put("APPLICATION_NAME", ce.getServletContext().getServletContextName());
EJB :-
MDC.put("APPLICATION_NAME", evt.getApplicationContext().getApplicationName();


Alas as the lifecycle listener events are handled on a seperate thread where exceptions occur the MDC, being effectively a threadlocal hashmap, returns null when I attempt to retrieve the name of the app.

I was wondering if anyone could think of a cleaner way of doing this? Perhaps using JMX or even by binding the contextClassLoader (which seems to remain the same across the threads into the JNDI tree with the application name)? Or else if anyone can think of any neater way of doing this that would be great.

Thanks,
Mark.
reply
    Bookmark Topic Watch Topic
  • New Topic