[slf4j-user] Library best practice

Martin Jericho mart1041 at yahoo.com.au
Sat Mar 10 16:10:30 CET 2007


I've been reading the thread in the dev forum about moving the LoggerFactory 
to the API, and being a SLF4J newbie I would appreciate it if someone could 
help me with a couple of basic questions.

I have a library in which I would like to use SLF4J for logging.

Q1.  Is the "typical usage pattern" in the user manual valid for library 
classes?  I would have thought that the user of the library would set the 
Logger instance via a setter method rather than it being instatiated 
automatically by the class itself.  I suspect however that library classes 
are supposed to instantiate their own Loggers, otherwise why were people 
complaining that the LoggerFactory wasn't in the API?

Q2.  If library classes are indeed supposed to instantiate their own 
Loggers, am I right in assuming that there is to be a Logger for each class, 
rather than one for the library as a whole?  Would it be considered very bad 
practice if there was only one Logger for the whole library, having the name 
of the package rather than a single class?

Q3.  I would still like to know the answer to the question I posed a few 
hours ago, which is how the classloader knows at runtime that it should use 
the LoggerFactory from the implementation jar instead of the "dummy" one in 
the API jar.

Thanks very much for any help.
Martin 

Send instant messages to your online friends http://au.messenger.yahoo.com 



More information about the slf4j-user mailing list