[slf4j-dev] [Bug 133] Add ability to log at a dynamic level

bugzilla-daemon at pixie.qos.ch bugzilla-daemon at pixie.qos.ch
Fri Jun 12 00:01:01 CEST 2009


http://bugzilla.slf4j.org/show_bug.cgi?id=133





--- Comment #4 from Robert Elliot <robert at teviotia.co.uk>  2009-06-12 00:01:00 ---
As Zoltan says, some classes may not know at compile time what level users want
their instances to log at at runtime.  Different instances of the same class
may need to log at different levels at the same point in the code.

SLF4J does have a concept of "levels" (or whatever you want to call them), just
no explicit enumerated type - every time you decide to type log.debug rather
than log.error you are choosing a level at which to log.

If you use the underlying logging system's levels then you have tied yourself
to a logging system rather than using the interface.

As to the ints being a hack - since SLF4J has to be compatible with Java 1.3 it
can't have "proper" enums.  It could of course be done using the typesafe enum
pattern, but as org.slf4j.spi.LocationAwareLogger was already logging via a
level and using ints as the enumeration mechanism I piggy-backed on it.

My particular use case was from the Sysout over SLF4J library, so indeed from a
logging product (I use two instances of the same class, one for sysout and one
for syserr, and the sysout instance needs to log at info and the syserr
instance at error).  I could of course do it using a switch statement or
if/else blocks, it just seemed ugly and likely that others would find
themselves doing the same thing, so it seemed a good candidate for a library
function.


-- 
Configure bugmail: http://bugzilla.slf4j.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.



More information about the slf4j-dev mailing list