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.