[logback-user] Logger level from Layout class

gaston sponer gaston.sponer at hotmail.com
Tue Jul 30 21:58:22 CEST 2013


Of course logger must be instantiated, we are good with that. I'm doing the instantiation of my logger in other class. 

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:
log = (Logger)LoggerFactory.getLogger("employee");
then i can follow your advice:
level=log.getLevel.toString();
I could be wrong but, isn´t it a dirty way to get just a level ?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.
I hope to be clear on what i want.
Thanks guysFrom: Forums at gombers.de
Date: Tue, 30 Jul 2013 21:37:58 +0200
To: logback-user at qos.ch
Subject: Re: [logback-user] Logger level from Layout class

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?Otherwise do a "String level=log.getLevel.toString()"
Ulrich

Am 30.07.2013 um 21:18 schrieb David Roussel <nabble at diroussel.xsmail.com>:

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/bb05fd63/attachment.html>


More information about the Logback-user mailing list