[logback-dev] Better introspection into logging setup

Durchholz, Joachim Joachim.Durchholz at hennig-fahrzeugteile.de
Tue Mar 2 13:50:11 CET 2010


> Although you have a point about SLF4J loggers having a 
> "notion" of levels, there is no SLF4J API to set or get 
> levels of the logging backend. The SLF4J allows for checking 
> whether a given logger is enabled for some level, but you 
> can't actually get the level of a logger nor can you set it.

The ability to check the level is enough to get the logger level. Just
try the isXxxEnabled functions.
(It's not efficient and ugly that way, but it would be good enough if
done just once per JUL logger.)

> I think this problem can not be dealt with abstractly for all 
> backends.

I'm not sure about that.
JUL needs a list of logger names and associated levels.
That's the same information that SLF4J uses to decide what to return for
LoggerFactory#getLogger(String) and Logger#isXxxEnabled.

Ah. It's actually not SLF4J that uses this information, it's the
backend.
So the real question is whether all backends provide a list of Loggers
or not.
Checking the list of available SLF4J backend:
- logback-classic: ok
- log4j: ?
- java.util.logging: yes but irrelevant for the JUL bridge :)
- simple: can fake a logger list
- nop: can fake a logger list
- jcl: ?

So, do log4j and jcl return a list of all active Loggers, or is there
some other API that allows inferring the list?

(The next question would be whether all backends provide hooks for
listening to changes in the list of Loggers.)

Regards,
Jo


More information about the logback-dev mailing list