[slf4j-user] Idiom for declaring loggers

Ceki Gulcu listid at qos.ch
Sat May 3 19:09:38 CEST 2008



Jacob Kjome wrote:
> Newcomb, Michael-P57487 wrote:
>> private static final Logger log = LoggerFactory.getLogger(<myclass>.class);
>>
>> IMHO, all loggers should be at a minimum private. It bothers me when you see a log in a file that says:
>>
>> [ClassC] some log statement
>>
>> Only to go to ClassC.java and you can't find the log statement! Then you realize that the variable was declared in the super class ClassB.
>>
>> As far as Endre is concerned he is correct. A static Logger solves this problem as well...
>>
> 
> Except that static logger breaks the repostitory selector concept along with other
> related problems.  Although, as I recall Ceki mentioning, so does simply using
> SLF4J or commons-logging instead of Log4j or Logback* directly, even when using
> non-static loggers.  So what's the solution there?  Don't use statics, at least
> for library code (but follow strict guidelines which are...???), and don't use a
> logging facade unless the implementation directly implements the facade?
> 
> http://wiki.apache.org/jakarta-commons/Logging/StaticLog


The above document contains valuable information. Pity that it is using the
term "TCCL-aware" instead of repository selectors.

> * Logback is the only case where using the SLF4J API doesn't have this problem
> because the implementation directly implements the SLF4J interfaces instead of
> redirecting to the real implementation

Hi Jake,

You are right, repository selectors do not work for SLF4J+log4j or
JCL+log4j combinations. A native implementation such as logback is
needed for repository selectors to work well.


At this stage of discussion, it seems unreasonable to ask
developers to all declare non-static loggers when:

1) the common idiom calls for static loggers
2) non-static loggers have a significant computational cost at initialization
3) need to be declared as transient in serialized classes
4) few applications are known to use repository selectors
5) repository selectors do not work for the SLF4J+log4j combination

That's a lot of counter arguments for non-static loggers.

> Jake

-- 
Ceki Gülcü
QOS.ch is looking to hire talented developers in Switzerland.  If
interested, please contact c e k i AT q o s . c h




More information about the slf4j-user mailing list