I thing you should check if the level is != null, i.e.<br><br>if (log.getLevel() != null) {<br>&nbsp;&nbsp;&nbsp; strList.add(log.getName());<br>}<br><br>cheers<br>jl<br><br><div class="gmail_quote">On Tue, Nov 11, 2008 at 05:07, Gunnar Hillert <span dir="ltr">&lt;<a href="mailto:gunnar@hillert.com">gunnar@hillert.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>
How do I get a list of configured loggers (In logback.xml) programmatically?<br>
<br>
e.g. I have the following loggers configured in my logback.xml file:<br>
<br>
...<br>
 &nbsp;&lt;logger name=&quot;org.springframework.security&quot;&gt;<br>
 &nbsp; &nbsp;&lt;level value=&quot;DEBUG&quot;/&gt;<br>
 &nbsp;&lt;/logger&gt;<br>
 &nbsp;&lt;logger name=&quot;org.apache.struts&quot;&gt;<br>
 &nbsp; &nbsp;&lt;level value=&quot;INFO&quot;/&gt;<br>
 &nbsp;&lt;/logger&gt;<br>
...<br>
<br>
How do I get those loggers? (E.g. I like to dynamically inspect and change<br>
my setup loggers at runtime)<br>
<br>
I was able to do this easily in Log4J but I seem to have issues doing so in<br>
logback.<br>
<br>
I thought I could do:<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;LoggerContext lc =<br>
((ch.qos.logback.classic.Logger)LOGGER).getLoggerContext();<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;List&lt;String&gt; strList = new ArrayList&lt;String&gt;();<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Iterator&lt;ch.qos.logback.classic.Logger&gt; it =<br>
lc.getLoggerList().iterator();<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;while(it.hasNext()) {<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Logger log = it.next();<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;strList.add(log.getName());<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>
<br>
But this basically adds hundreds of loggers but I only want the ones I have<br>
configured in my logback.xml file.<br>
<br>
What do I miss here?<br>
<br>
Thanks a lot!<br>
<br>
Gunnar<br>
<font color="#888888"><br>
<br>
--<br>
View this message in context: <a href="http://www.nabble.com/How-do-I-get-a-list-of-configured-loggers--tp20433216p20433216.html" target="_blank">http://www.nabble.com/How-do-I-get-a-list-of-configured-loggers--tp20433216p20433216.html</a><br>

Sent from the Logback User mailing list archive at Nabble.com.<br>
<br>
_______________________________________________<br>
Logback-user mailing list<br>
Logback-user@qos.ch<br>
<a href="http://qos.ch/mailman/listinfo/logback-user" target="_blank">http://qos.ch/mailman/listinfo/logback-user</a><br>
</font></blockquote></div><br>