<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>If you are inside the layout, then get the level from the event. That is the one and only place to get the level from.  <br><br>David</div><div><br>On 30 Jul 2013, at 20:58, gaston sponer <<a href="mailto:gaston.sponer@hotmail.com">gaston.sponer@hotmail.com</a>> wrote:<br><br></div><blockquote type="cite"><div>

<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style>
<div dir="ltr">Of course logger must be instantiated, we are good with that. I'm doing the instantiation of my logger in other class. <br><br><div>I can´t do String level=log.getLevel.toString(), because from MyLayout class i don't have access to my logger. Unless of course, i do this:</div><div><br></div><div><span style="font-family: Calibri; orphans: 2; widows: 2;">log = (Logger)LoggerFactory.getLogger("employee");</span></div><div><div style="orphans: 2; widows: 2;"><font face="Calibri"><br></font></div><div style="orphans: 2; widows: 2;"><font face="Calibri">then i can follow your advice:</font></div><div style="orphans: 2; widows: 2;"><font face="Calibri"><b><br></b></font></div><div style="orphans: 2; widows: 2;"><span style="orphans: auto; widows: auto;">level=log.getLevel.toString();</span></div><div style="orphans: 2; widows: 2;"><span style="orphans: auto; widows: auto;"><br></span></div><div style="orphans: auto; widows: auto;">I could be wrong but, isn´t it a dirty way to get just a level ?</div><div style="orphans: auto; widows: auto;">I was thinking maybe on get the logger level from MyLayout event (param from doLayout), but i can´t find any logger level, just event.getLevel(), and that is a differente one.</div><div style="orphans: auto; widows: auto;"><br></div><div style="orphans: auto; widows: auto;">I hope to be clear on what i want.</div><div style="orphans: auto; widows: auto;"><br></div><div style="orphans: auto; widows: auto;">Thanks guys</div><div><hr id="stopSpelling">From: <a href="mailto:Forums@gombers.de">Forums@gombers.de</a><br>Date: Tue, 30 Jul 2013 21:37:58 +0200<br>To: <a href="mailto:logback-user@qos.ch">logback-user@qos.ch</a><br>Subject: Re: [logback-user] Logger level from Layout class<br><br><div>I don't understand the question anyway. If there is no need for a logger (that is, if it shall not become instantiated), what does it mean to know the log-level. Which routine shall read the config, if the logger isn't instantiated?</div><div>Otherwise do a "String level=log.getLevel.toString()"</div><div><br></div><div>Ulrich</div><div><br></div><div><br>Am 30.07.2013 um 21:18 schrieb David Roussel <<a href="mailto:nabble@diroussel.xsmail.com">nabble@diroussel.xsmail.com</a>>:<br><br></div><blockquote><div><div>Gaston,</div><div><br></div><div>Normally if you need to do something based on the logging level, you'd do.</div><div><br></div><div>if (log.isDebugEnabled()) {</div><div> …</div><div>}</div><div><br></div><div>Is there some special reason why you'd need the exact level?</div><div><br></div><div>David</div><br><div><div>On 30 Jul 2013, at 19:33, gaston sponer <<a href="mailto:gaston.sponer@hotmail.com">gaston.sponer@hotmail.com</a>> wrote:</div><br class="ecxApple-interchange-newline"><blockquote><div class="ecxhmmessage" style="font-size:12pt;font-family:Calibri;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;orphans:2;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;widows:2;word-spacing:0px;"><div dir="ltr">Hi, Is there any way to get from MyLayout the logger level? I don't want to do this:<div><br></div><div><div>package com.render;</div><div><span style="font-size:12pt;">import org.slf4j.LoggerFactory;</span></div><div><span style="font-size:12pt;">import ch.qos.logback.classic.Logger;</span></div><div>import ch.qos.logback.classic.spi.ILoggingEvent;</div><div>import ch.qos.logback.core.LayoutBase;</div><div><br></div><div>import com.render.domain.Employee;</div><div><br></div><div>public class MyLayout extends LayoutBase<ILoggingEvent>{</div><div><span class="ecxApple-tab-span" style="white-space:pre;">     </span></div><div><span class="ecxApple-tab-span" style="white-space:pre;">         </span><b>String level= ((Logger)LoggerFactory.getLogger("employee")).getLevel().toString();</b></div><div>...</div><div>...</div><div><br></div><div>This works well but i don't like to instantiate an object just to get a logger level.</div><div><br></div><div><br></div><div>This is my xml config file:</div><div><br></div><div><div><span style="font-size:12pt;"><configuration></span></div><div><span style="font-size:12pt;"><logger name="employee" level="debug"/></span></div><div><span class="ecxApple-tab-span" style="font-size:12pt;white-space:pre;">        </span><span style="font-size:12pt;"><appender name="CONSOLE" </span><span style="font-size:12pt;">class="ch.qos.logback.core.ConsoleAppender"></span></div><div><span class="ecxApple-tab-span" style="white-space:pre;">               </span><encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder"></div><div>     <span class="ecxApple-converted-space"> </span><span class="ecxApple-tab-span" style="white-space:pre;">                </span><layout class="com.render.MyLayout"  ></div><div>     <span class="ecxApple-converted-space"> </span><span class="ecxApple-tab-span" style="white-space:pre;">                </span></layout></div><div>   <span class="ecxApple-converted-space"> </span><span class="ecxApple-tab-span" style="white-space:pre;">   </span></encoder></div><div>    </appender><span class="ecxApple-tab-span" style="white-space:pre;">  </span></div><div><span class="ecxApple-tab-span" style="white-space:pre;"> </span></div><div><span class="ecxApple-tab-span" style="white-space:pre;"> </span><root level="off"></div><div><span class="ecxApple-tab-span" style="white-space:pre;">               </span><appender-ref ref="CONSOLE" /></div><div><span class="ecxApple-tab-span" style="white-space:pre;">   </span></root></div><div></configuration></div><div><br></div></div><div><br></div><div>Thanks,</div><div>Gastón.</div><div><br></div></div></div>_______________________________________________<br>Logback-user mailing list<br><a href="mailto:Logback-user@qos.ch">Logback-user@qos.ch</a><br><a href="http://mailman.qos.ch/mailman/listinfo/logback-user" target="_blank">http://mailman.qos.ch/mailman/listinfo/logback-user</a></div></blockquote></div><br></div></blockquote><blockquote><div><span>_______________________________________________</span><br><span>Logback-user mailing list</span><br><span><a href="mailto:Logback-user@qos.ch">Logback-user@qos.ch</a></span><br><span><a href="http://mailman.qos.ch/mailman/listinfo/logback-user" target="_blank">http://mailman.qos.ch/mailman/listinfo/logback-user</a></span></div></blockquote><br>_______________________________________________
Logback-user mailing list
<a href="mailto:Logback-user@qos.ch">Logback-user@qos.ch</a>
<a href="http://mailman.qos.ch/mailman/listinfo/logback-user">http://mailman.qos.ch/mailman/listinfo/logback-user</a></div></div>                                       </div>
</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>Logback-user mailing list</span><br><span><a href="mailto:Logback-user@qos.ch">Logback-user@qos.ch</a></span><br><span><a href="http://mailman.qos.ch/mailman/listinfo/logback-user">http://mailman.qos.ch/mailman/listinfo/logback-user</a></span></div></blockquote></body></html>