[slf4j-user] Need Help

Chris Broussard cbroussard at liquiddatainc.com
Thu Nov 30 04:26:36 CET 2006


I'm new to slf4j, and I'm having problems figuring things out..   
Would like to start using slf4j & logback instead of log4j/commons  
logging/etc.

I'm trying to load a custom xml configuration file, and get the  
following status messages

20:56:10,391 INFO  [STDOUT] |-INFO in  
ch.qos.logback.core.joran.action.AppenderAction - About to  
instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
20:56:10,392 INFO  [STDOUT] |-INFO in  
ch.qos.logback.core.joran.action.AppenderAction - Naming appender as  
[STDOUT]
20:56:10,393 INFO  [STDOUT] |-INFO in  
ch.qos.logback.core.joran.action.NestedComponentIA - is dmmed  
applicable for /configuration/appender/layout
20:56:10,394 INFO  [STDOUT] |-INFO in  
ch.qos.logback.core.joran.action.NestedComponentIA - Pushing  
component <layout> on top of the object stack.
20:56:10,394 INFO  [STDOUT] |-INFO in  
ch.qos.logback.core.joran.action.AppenderAction - Popping appender  
named [STDOUT] from the object stack
20:56:10,394 INFO  [STDOUT] |-INFO in  
ch.qos.logback.core.joran.action.AppenderAction - About to  
instantiate appender of type [ch.qos.logback.core.FileAppender]
20:56:10,395 INFO  [STDOUT] |-INFO in  
ch.qos.logback.core.joran.action.AppenderAction - Naming appender as  
[FILE]
20:56:10,395 INFO  [STDOUT] |-INFO in  
ch.qos.logback.core.joran.action.NestedComponentIA - is dmmed  
applicable for /configuration/appender/layout
20:56:10,395 INFO  [STDOUT] |-INFO in  
ch.qos.logback.core.joran.action.NestedComponentIA - Pushing  
component <layout> on top of the object stack.
20:56:10,395 INFO  [STDOUT] |-INFO in  
ch.qos.logback.core.joran.action.AppenderAction - Popping appender  
named [FILE] from the object stack
20:56:10,396 INFO  [STDOUT] |-ERROR in  
ch.qos.logback.core.joran.spi.InterpretationContext at c907a1 - no  
applicable action for <logger>, current pattern is [/configuration/ 
logger]
20:56:10,396 INFO  [STDOUT] |-ERROR in  
ch.qos.logback.core.joran.spi.InterpretationContext at c907a1 - no  
applicable action for <level>, current pattern is [/configuration/ 
logger/level]
20:56:10,397 INFO  [STDOUT] |-ERROR in  
ch.qos.logback.core.joran.spi.InterpretationContext at c907a1 - no  
applicable action for <root>, current pattern is [/configuration/root]
20:56:10,397 INFO  [STDOUT] |-ERROR in  
ch.qos.logback.core.joran.spi.InterpretationContext at c907a1 - no  
applicable action for <level>, current pattern is [/configuration/ 
root/level]
20:56:10,397 INFO  [STDOUT] |-ERROR in  
ch.qos.logback.core.joran.spi.InterpretationContext at c907a1 - no  
applicable action for <appender-ref>, current pattern is [/ 
configuration/root/appender-ref]
20:56:10,397 INFO  [STDOUT] |-ERROR in  
ch.qos.logback.core.joran.spi.InterpretationContext at c907a1 - no  
applicable action for <appender-ref>, current pattern is [/ 
configuration/root/appender-ref]


Here's the java class

import org.slf4j.ILoggerFactory;
import org.slf4j.Logger;
import org.slf4j.impl.StaticLoggerBinder;
import org.slf4j.impl.Util;

import ch.qos.logback.access.joran.JoranConfigurator;
import ch.qos.logback.core.Context;
import ch.qos.logback.core.util.Loader;
import ch.qos.logback.core.util.StatusPrinter;

public class LogServicesFactory{

	    private LogServicesFactory()
	    {
	    }

	    public static Logger getLogger(String name)
	    {
	        return loggerFactory.getLogger(name);
	    }

	    public static Logger getLogger(Class clazz)
	    {
	        return loggerFactory.getLogger(clazz.getName());
	    }

	    public static ILoggerFactory getILoggerFactory()
	    {
	        return loggerFactory;
	    }

	    static ILoggerFactory loggerFactory;

	    static
	    {
	        try
	        {
	            loggerFactory =  
StaticLoggerBinder.SINGLETON.getLoggerFactory();
	            java.net.URL url = Loader.getResource("/com/frostylabs/ 
common/logging/logservices.xml");
	            if(url != null)
	            {
	                JoranConfigurator configurator = new  
JoranConfigurator();
	                configurator.setContext((Context)loggerFactory);
	                configurator.doConfigure(url);
	                StatusPrinter.print((Context)loggerFactory);
	            }
	        }
	        catch(Exception e)
	        {
	            Util.reportFailure((new StringBuilder()).append("Failed  
to instantiate logger [").append 
(StaticLoggerBinder.SINGLETON.getLoggerFactoryClassStr()).append 
("]").toString(), e);
	        }
	    }

} /* end class */


Here's the sample xml configuration

<?xml version="1.0" encoding="UTF-8" ?>
<configuration>

   <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
     <layout class="ch.qos.logback.classic.PatternLayout">
       <param name="pattern" value="%-4relative [%thread] %-5level % 
class - %msg%n" />
     </layout>
   </appender>

   <appender name="FILE"  class="ch.qos.logback.core.FileAppender">
     <layout class="ch.qos.logback.classic.PatternLayout">
       <param name="pattern" value="%-4relative [%thread] %-5level % 
class - %msg%n" />
     </layout>
     <param name="File" value="/tmp/estest.txt" />
   </appender>

   <logger name="com.frostylabs">
     <level value="debug" />
   </logger>

   <root>
     <level value="debug" />
     <appender-ref ref="STDOUT" />
     <appender-ref ref="FILE" />
   </root>

</configuration>


My classpath has logback-access.jar, logback-core.jar, logback- 
classic.jar, slf4j-api-1.1.0-RC1.jar in it.  I'm running it on jboss/ 
tomcat & cactus/junit, but my test case is hitting slf4j directly.

calling the getLogger().debug, getLogger().info, etc doesn't log  
anything into the test file or the console.

Any ideas ?  Much appreciation...

Chris



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://qos.ch/pipermail/slf4j-user/attachments/20061129/3b019192/attachment.htm>


More information about the slf4j-user mailing list