[slf4j-user] Library best practice
Boris Unckel
boris.unckel.mlg at gmx.net
Sun Mar 11 16:49:18 CET 2007
Hi Martin,
Martin Jericho wrote:
> 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?
>
Two things:
1) Do not use a static a logger, obtain the logger in the class itself.
> 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?
>
>
2) Use a logger per class, the configuration of the underlying log
system can be used to configure the
levels and handlers/appenders/filters per package. But you still have
the flexibility to configure it
per 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.
Other mail in this thread.
Regards
Boris.
More information about the slf4j-user
mailing list