[slf4j-user] Need Help

Sebastien Pennec sebastien at qos.ch
Thu Nov 30 11:51:31 CET 2006


Hello Chris,

Thanks for using logback :)

I've just checked your configuration file, and it worked fine.

The problem is that you are importing the *access* module's JoranConfigurator. Since 
the access module has no knowledge of logger or level objects, it cannot configure them.

Try importing

ch.qos.logback.classic.joran.JoranConfigurator

instead of

ch.qos.logback.access.joran.JoranConfigurator

It should solve the problem.

Are you using access-log *and* normal logging? If you want to use logback to provide 
access logging functionalities to your container, then the logback-access jar must be 
present, but if you only intend to use logback as a logging implementation behind 
SLF4J, then the logback-access jar is not useful, and might be taken off the 
classpath. This will also prevent problems like the one you are facing.

Hope this helps,

Cheers,

Sébastien


Chris Broussard a écrit :
> 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
> 
> 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> user mailing list
> user at slf4j.org
> http://www.slf4j.org/mailman/listinfo/user

-- 
Sébastien Pennec
sebastien at qos.ch

Logback: The reliable, generic, fast and flexible logging framework for Java.
http://logback.qos.ch/



More information about the slf4j-user mailing list