8

I'm trying to set up a console logger with logback in slf4j. My logback configuration is as follows:

<configuration>

  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
  <!-- encoders are assigned the type
       ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
    <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
      <pattern>%-4relative [%thread] %-5level %logger{35} - %msg %n</pattern>
    </encoder>
  </appender>

  <logger name="org.hibernate" level="INFO" />
  <logger name="com.myapp" level="TRACE" />

  <root level="DEBUG">
    <appender-ref ref="STDOUT" />
  </root>
</configuration>

Even though Logback seems to set up with no problems, I can't seem to get output from any loggers into my console. I have tested that LOGGER.isInfoEnabled() returns true in my app.

The output of Logback's StatusPrinter:

17:25:11,736 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
17:25:11,737 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [file:/Users/ryanspicer/NetBeansProjects/Oncewhen/build/classes/logback.xml]
17:25:11,996 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - debug attribute not set
17:25:11,996 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
17:25:12,000 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [STDOUT]
17:25:12,038 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@12:74 - no applicable action for [encoder], current pattern is [[configuration][appender][encoder]]
17:25:12,038 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@13:16 - no applicable action for [pattern], current pattern is [[configuration][appender][encoder][pattern]]
17:25:12,038 |-ERROR in ch.qos.logback.core.ConsoleAppender[STDOUT] - No layout set for the appender named "STDOUT".
17:25:12,038 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Popping appender named [STDOUT] from the object stack
17:25:12,038 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.hibernate] to INFO
17:25:12,038 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting additivity of logger [org.hibernate] to true
17:25:12,038 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [com.myapp] to TRACE
17:25:12,038 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting additivity of logger [com.myapp] to true
17:25:12,038 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to DEBUG
17:25:12,038 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [STDOUT] to Logger[root]

Any ideas what might be going on here, and how to fix it and get working log output?

Alterscape
  • 1,526
  • 1
  • 17
  • 34

2 Answers2

5

From the status output, it looks like you are using a version of logback 0.9.18 or earlier. You should try with the latest version.

Ceki
  • 26,753
  • 7
  • 62
  • 71
  • 1
    I'm accepting this because it put me on the trail of the actual problem -- the Xuggler video library (which insists on being installed into /usr/ and going in the global classpath) was providing an old Logback jar, which was confusing slf4j. After I updated to the latest Logback and SLF4J inside my project, I was able to coerce slf4j to bind to the correct Logback, and all was well. – Alterscape Sep 17 '12 at 02:04
  • I am using the latest version of logback (1.0.9) and I am still seeing these ERROR messages. Any idea why that may be? Thanks. Eugen. – Eugen Dec 21 '12 at 18:20
  • The version of logback-classic.jar and logback-core.jar should match. – Ceki Dec 21 '12 at 18:46
1

For those who need to use logback 0.9.18 due to third party dependencies, see this answer for an example of how to configure the appenders.

logback with EJB3.1

Community
  • 1
  • 1
Dan Collins
  • 345
  • 4
  • 6