[logback-user] How do I get a list of configured loggers?

Jean-Luc Geering jgeering at optaros.com
Tue Nov 11 10:09:17 CET 2008


I thing you should check if the level is != null, i.e.

if (log.getLevel() != null) {
    strList.add(log.getName());
}

cheers
jl

On Tue, Nov 11, 2008 at 05:07, Gunnar Hillert <gunnar at hillert.com> wrote:

>
> How do I get a list of configured loggers (In logback.xml)
> programmatically?
>
> e.g. I have the following loggers configured in my logback.xml file:
>
> ...
>  <logger name="org.springframework.security">
>    <level value="DEBUG"/>
>  </logger>
>  <logger name="org.apache.struts">
>    <level value="INFO"/>
>  </logger>
> ...
>
> How do I get those loggers? (E.g. I like to dynamically inspect and change
> my setup loggers at runtime)
>
> I was able to do this easily in Log4J but I seem to have issues doing so in
> logback.
>
> I thought I could do:
>
>                LoggerContext lc =
> ((ch.qos.logback.classic.Logger)LOGGER).getLoggerContext();
>                List<String> strList = new ArrayList<String>();
>                Iterator<ch.qos.logback.classic.Logger> it =
> lc.getLoggerList().iterator();
>                while(it.hasNext()) {
>                  Logger log = it.next();
>                  strList.add(log.getName());
>                }
>
> But this basically adds hundreds of loggers but I only want the ones I have
> configured in my logback.xml file.
>
> What do I miss here?
>
> Thanks a lot!
>
> Gunnar
>
>
> --
> View this message in context:
> http://www.nabble.com/How-do-I-get-a-list-of-configured-loggers--tp20433216p20433216.html
> Sent from the Logback User mailing list archive at Nabble.com.
>
> _______________________________________________
> Logback-user mailing list
> Logback-user at qos.ch
> http://qos.ch/mailman/listinfo/logback-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://qos.ch/pipermail/logback-user/attachments/20081111/6ac6bccd/attachment.htm 


More information about the Logback-user mailing list