[slf4j-user] Is it not safe to store the Logger instance into a static field?
Ceki Gülcü
listid at qos.ch
Fri Mar 3 11:55:17 CET 2006
Hello Ruimo,
JCL documentation (in wiki?) supposedly discusses this issue. Simon
Kitching discusses this problem on the jakarta commons dev mailing list.
Here is what Simon has to say on the subject.
http://marc.theaimsgroup.com/?l=jakarta-commons-dev&m=113537357512186&w=2
Unfortunately, I could not find the FAQ entry Simon is referring to.
A document called "Supporting the log4j RepositorySelector in Servlet
Containers" [1] attempts to explain the different effects of static and
instance logger fields from the perspective of pure logging, i.e. in the
the absence of bugs.
The existence of bugs in Tomcat adds another dimension to the question.
Slf4j bug report #15 (see [2]) and Tomcat bug report #38579 (see [3])
document Tomcat's behavior in relation to *final* static fields. In short,
Tomcat's WebClassLoader nulls the fields contained *within* static final
fields. This bug is not SLF4J specific. It is not even logging specific.
Also keep in mind that even if you don't use static final fields, many
libraries that you might depend, can and actually do have final static fields.
A little investigation shows that the incriminated nullInstance(Object)
method was added to the WebappClassLoader class on Nov 17 12:10:48 2005
UTC. The bug was fixed on Feb 16 14:19:13 2006 UTC. Tomcat versions
released before 2005-11-17 or after 2006-02-16 should not suffer from this
bug.
Looking at Tomcat releases [5], I'd would avoid Tomcat versions 5.5.14
through 5.5.15 (inclusive). Tomcat 5.5.12 should be OK. When they are
released, Tomcat versions 5.1.16 and later should also be OK.
Anyway, the question merits further discussion and needs to be better
documented.
Cheers,
[1] http://www.qos.ch/logging/sc.jsp
[2] http://bugzilla.slf4j.org/show_bug.cgi?id=15
[3] http://issues.apache.org/bugzilla/show_bug.cgi?id=38579
[4] http://tinyurl.com/l7nch
[5] http://www.apache.org/dist/tomcat/tomcat-5/
--
Ceki Gülcü
http://ceki.blogspot.com/
More information about the slf4j-user
mailing list