<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>Oh, thanks Chris.. I will go for encoder pattern way.<br><br><div><hr id="stopSpelling">From: thechrispratt@gmail.com<br>Date: Tue, 30 Jul 2013 12:44:42 -0700<br>To: logback-user@qos.ch<br>Subject: Re: [logback-user] Logger level from Layout class<br><br><div dir="ltr">That's the job of the log encoder pattern, you shouldn't be doing that in your code, use the %p placeholder in your pattern string in your configuration file. See <a href="http://logback.qos.ch/manual/configuration.html" target="_blank">http://logback.qos.ch/manual/configuration.html</a> for more information<div>
(*Chris*)</div></div><div class="ecxgmail_extra"><br><br><div class="ecxgmail_quote">On Tue, Jul 30, 2013 at 12:40 PM, gaston sponer <span dir="ltr"><<a href="mailto:gaston.sponer@hotmail.com" target="_blank">gaston.sponer@hotmail.com</a>></span> wrote:<br>
<blockquote class="ecxgmail_quote" style="border-left:1px #ccc solid;padding-left:1ex;">
<div><div dir="ltr">I need to show logger level on my log. <div>Ex:</div><div><br></div><div>Log:</div><div>event level: ERROR logger level: <font color="#d24726"><b>debug </b></font>[main] Company_Module - Personal: name=John, age=36, id=3124362]</div>
<div><br></div><div>I understand isDebugEnabled, but this is not what i'm looking. My logger levele (set on xml config file) could be any level (info, trace, error, debug...) is not about debug level, is about print the level from logger that i can set on xml.</div>
<div><br></div><div>If i had this in my xml :</div><div><span style="font-family:Calibri;"><logger name="employee" level="info"/></span></div><div><br></div><div><font face="Calibri">my log would print :</font></div>
<div><br><div>event level: ERROR logger level: <font color="#d24726"><b>info</b></font>[main] Company_Module - Personal: name=John, age=36, id=3124362]</div><div><br></div><div>My concern is about what other way exist to get logger level different what i'm using now:</div>
<div class="ecxim"><div><br></div><div><b style="font-family:Calibri;">String level= ((Logger)LoggerFactory.getLogger("employee")).getLevel().toString();</b></div><div><b style="font-family:Calibri;"><br></b></div></div>
<div><span><div style="font-family:Calibri;">public String doLayout(ILoggingEvent event) {</div><div style="font-family:Calibri;"><span style="white-space:pre-wrap;"> </span> StringBuffer sbuf = new StringBuffer(128);</div>
<div style="font-family:Calibri;"><span style="white-space:pre-wrap;"> </span> sbuf.append("event level: ");</div><div style="font-family:Calibri;"><span style="white-space:pre-wrap;"> </span> sbuf.append(event.getLevel());</div>
<div style="font-family:Calibri;"><span style="white-space:pre-wrap;"> </span> sbuf.append(" logger level: ");</div><div style="font-family:Calibri;"><span style="white-space:pre-wrap;"> </span> sbuf.append(getLevel());</div>
<div style="font-family:Calibri;"><span style="white-space:pre-wrap;"> </span> sbuf.append(" [");</div><div style="font-family:Calibri;"><span style="white-space:pre-wrap;"> </span> sbuf.append(event.getThreadName());</div>
<div style="font-family:Calibri;"><span style="white-space:pre-wrap;"> </span> sbuf.append("] ");</div><div style="font-family:Calibri;"><span style="white-space:pre-wrap;"> </span> sbuf.append(event.getLoggerName());</div>
<div style="font-family:Calibri;"><span style="white-space:pre-wrap;"> </span> sbuf.append(" - ");</div><div><font face="Calibri"> logMsg.append(employee.getPerson());</font></div><div style="font-family:Calibri;">
<span style="white-space:pre-wrap;"> </span> return sbuf.toString();</div><div style="font-family:Calibri;">}</div><div style="font-family:Calibri;"><br></div><div><div><font face="Calibri">public String getLevel() {</font></div>
<div><font face="Calibri"><span style="white-space:pre-wrap;"> </span>return level;</font></div><div><font face="Calibri"> }</font></div><div><font face="Calibri"><br></font></div><div><font face="Calibri">public void setLevel(String level) {</font></div>
<div><font face="Calibri"><span style="white-space:pre-wrap;"> </span>this.level = level;</font></div><div><font face="Calibri">}</font></div></div><div style="font-family:Calibri;"><span style="white-space:pre-wrap;"> </span> </div>
</span></div><div>Thanks,</div><div><br></div><div>Gaston</div><div><hr>From: <a href="mailto:nabble@diroussel.xsmail.com" target="_blank">nabble@diroussel.xsmail.com</a><br>Date: Tue, 30 Jul 2013 20:18:37 +0100<br>To: <a href="mailto:logback-user@qos.ch" target="_blank">logback-user@qos.ch</a><br>
Subject: Re: [logback-user] Logger level from Layout class<div><div class="h5"><br><br><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" target="_blank">gaston.sponer@hotmail.com</a>> wrote:</div>
<br><blockquote><div style="font-size:12pt;font-family:Calibri;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;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 style="white-space:pre-wrap;"> </span></div><div><span style="white-space:pre-wrap;"> </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 style="font-size:12pt;white-space:pre-wrap;"> </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 style="white-space:pre-wrap;"> </span><encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder"></div><div> <span> </span><span style="white-space:pre-wrap;"> </span><layout class="com.render.MyLayout" ></div>
<div> <span> </span><span style="white-space:pre-wrap;"> </span></layout></div><div> <span> </span><span style="white-space:pre-wrap;"> </span></encoder></div><div> </appender><span style="white-space:pre-wrap;"> </span></div>
<div><span style="white-space:pre-wrap;"> </span></div><div><span style="white-space:pre-wrap;"> </span><root level="off"></div><div><span style="white-space:pre-wrap;"> </span><appender-ref ref="CONSOLE" /></div>
<div><span style="white-space:pre-wrap;"> </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" target="_blank">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><br>_______________________________________________
Logback-user mailing list
<a href="mailto:Logback-user@qos.ch" target="_blank">Logback-user@qos.ch</a>
<a href="http://mailman.qos.ch/mailman/listinfo/logback-user" target="_blank">http://mailman.qos.ch/mailman/listinfo/logback-user</a></div></div></div></div> </div></div>
<br>_______________________________________________<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><br></blockquote></div><br></div>
<br>_______________________________________________
Logback-user mailing list
Logback-user@qos.ch
http://mailman.qos.ch/mailman/listinfo/logback-user</div> </div></body>
</html>