[logback-dev] [Bug 84] LoggerContextFilter is useless (org.slf4j.Loggerfactory bug ++)

bugzilla-daemon at pixie.qos.ch bugzilla-daemon at pixie.qos.ch
Tue Sep 18 22:50:55 CEST 2007


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





------- Comment #3 from lars at koedderitzsch.net  2007-09-18 22:50 -------
Hello Ceki,
thanks for your response.
As Jens already pointed out the most common pattern to logging (even in common
libaries as Jakarta Commons, Spring whatsoever) is using a static logger, eg.
public class XY {
    private static [final] Logger log = LoggerFactory.getLogger(XY.class);
    ...
}

If such libraries are shared (either by being in tomcats shared libs, or by
being directly in the ear) by multiple webapps, the logger context wins in
which the original loading of the logging class (aka XY, see above) happens.

To make an example.
An ear contains two webapplications A and B, both have different logger context
CtxA and CtxB.
A library (say Spring for instance) is place in the ear and both webapps
reference the library through their MANIFEST.MF.
On application startup webapp A gets initialized first, during initialisation
the classes of the shared libary (Spring) are loaded, therefor static loggers
initialized with the context CtxA.
Now webapp B gets initialized, classes of the shared libary are already loaded
by the EARClassloader, the loggers continue to use CtxA.
At runtime regardless of wich logger context will be set by context selectors
of the webapps, all logging done by the shared classes will always go to CtxA.

One can argue that common libaries should not use static loggers, but always
obtain loggers freshly from the LoggerFactory. But that is a pipe dream,
because the de-facto pattern in obtaining and using a logger is through a
static field as depicted above.

To achieve true per-webapp logging, already initialized loggers need to be able
to switch logger contexts, for instance through TreadLocal or other mechanisms.


-- 
Configure bugmail: http://bugzilla.qos.ch/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.



More information about the logback-dev mailing list