[slf4j-user] Idiom for declaring loggers

Jacob Kjome hoju at visi.com
Thu May 1 07:58:23 CEST 2008


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

* 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


Jake



More information about the slf4j-user mailing list