[logback-user] Logger level from Layout class

Chris Pratt thechrispratt at gmail.com
Tue Jul 30 21:44:42 CEST 2013


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
http://logback.qos.ch/manual/configuration.htmlfor more information
  (*Chris*)


On Tue, Jul 30, 2013 at 12:40 PM, gaston sponer
<gaston.sponer at hotmail.com>wrote:

> I need to show logger level on my log.
> Ex:
>
> Log:
> event level: ERROR logger level: *debug *[main] Company_Module -
> Personal: name=John, age=36, id=3124362]
>
> 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.
>
> If i had this in my xml :
> <logger name="employee" level="info"/>
>
> my log would print :
>
> event level: ERROR logger level: *info*[main] Company_Module -  Personal:
> name=John, age=36, id=3124362]
>
> My concern is about what other way exist to get logger level different
> what i'm using now:
>
> *String level=
> ((Logger)LoggerFactory.getLogger("employee")).getLevel().toString();*
> *
> *
> public String doLayout(ILoggingEvent event) {
>     StringBuffer sbuf = new StringBuffer(128);
>     sbuf.append("event level: ");
>     sbuf.append(event.getLevel());
>     sbuf.append(" logger level: ");
>     sbuf.append(getLevel());
>     sbuf.append(" [");
>     sbuf.append(event.getThreadName());
>     sbuf.append("] ");
>     sbuf.append(event.getLoggerName());
>     sbuf.append(" - ");
>                     logMsg.append(employee.getPerson());
>     return sbuf.toString();
> }
>
> public String getLevel() {
>  return level;
>  }
>
> public void setLevel(String level) {
>  this.level = level;
> }
>
> Thanks,
>
> Gaston
> ------------------------------
> From: nabble at diroussel.xsmail.com
> Date: Tue, 30 Jul 2013 20:18:37 +0100
> To: logback-user at qos.ch
> Subject: Re: [logback-user] Logger level from Layout class
>
>
> Gaston,
>
> Normally if you need to do something based on the logging level, you'd do.
>
> if (log.isDebugEnabled()) {
>> }
>
> Is there some special reason why you'd need the exact level?
>
> David
>
> On 30 Jul 2013, at 19:33, gaston sponer <gaston.sponer at hotmail.com> wrote:
>
> Hi, Is there any way to get from MyLayout the logger level? I don't want
> to do this:
>
> package com.render;
> import org.slf4j.LoggerFactory;
> import ch.qos.logback.classic.Logger;
> import ch.qos.logback.classic.spi.ILoggingEvent;
> import ch.qos.logback.core.LayoutBase;
>
> import com.render.domain.Employee;
>
> public class MyLayout extends LayoutBase<ILoggingEvent>{
>  *String level=
> ((Logger)LoggerFactory.getLogger("employee")).getLevel().toString();*
> ...
> ...
>
> This works well but i don't like to instantiate an object just to get a
> logger level.
>
>
> This is my xml config file:
>
> <configuration>
> <logger name="employee" level="debug"/>
> <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
>  <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
>        <layout class="com.render.MyLayout"  >
>        </layout>
>      </encoder>
>     </appender>
>  <root level="off">
> <appender-ref ref="CONSOLE" />
>  </root>
> </configuration>
>
>
> Thanks,
> Gastón.
>
> _______________________________________________
> Logback-user mailing list
> Logback-user at qos.ch
> http://mailman.qos.ch/mailman/listinfo/logback-user
>
>
>
> _______________________________________________ Logback-user mailing list
> Logback-user at qos.ch http://mailman.qos.ch/mailman/listinfo/logback-user
>
> _______________________________________________
> Logback-user mailing list
> Logback-user at qos.ch
> http://mailman.qos.ch/mailman/listinfo/logback-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/logback-user/attachments/20130730/e33e1103/attachment.html>


More information about the Logback-user mailing list