[slf4j-user] Is it not safe to store the Logger instance into a static field?

Ceki Gülcü listid at qos.ch
Mon Mar 13 21:00:13 CET 2006


At 08:26 PM 3/13/2006, Simon Kitching wrote:
>On Mon, 2006-03-13 at 10:34 +0100, Ceki Gülcü wrote:
> > At 10:23 AM 3/13/2006, Trustin wrote:
> > >On 3/5/06, Simon Kitching
> > ><skitching at apache.org> wrote:
> > >>I've created a page specifically on this problem here:
> > >> http://wiki.apache.org/jakarta-commons/Logging/StaticLog
> > >
> > >Thanks, Simon!  What a wonderful page! :D
> >
> > +1
>
>Thank you both for your kind words.

It's a good page full of useful information.

You might want to consider changing the term "TCCL-aware" library 
to  something less TCCL-oriented. Logging separation is possible without 
referring to TCCL at all but instead to JNDI environment variables. The 
fact that the container itself keeps track of JNDI environment variables 
using the TCCL should be considered as an implementation detail of the 
container. Log4j 1.3alpha ships with ContextJNDISelector [1], a repository 
selector based on JNDI, which imho works remarkably well. As a direct 
consequence of ContextJNDISelector and its variants, a statically bound 
logging facade such as SLF4J can delegate the logging separation problem to 
the underlying logging system. Anyway, I believe the term "context-aware" 
to be more precise than TCCL-aware.

I should like to emphasize that the basic premise of your article remains 
valid. Static logger variables are highly detrimental to logging separation.

[1] 
http://logging.apache.org/log4j/docs/api-1.3/org/apache/log4j/selector/ContextJNDISelector.html

-- 
Ceki Gülcü
http://ceki.blogspot.com/




More information about the slf4j-user mailing list