Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logback.xml not logging to ConsoleAppender?

Tags:

java

logback

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?

like image 337
Alterscape Avatar asked Sep 16 '12 00:09

Alterscape


People also ask

How do I setup a Logback XML file?

In a Logback. xml file, all the configuration options are enclosed within the <configuration> root element. In the root element, you can set the debug=true attribute to inspect Logback's internal status. You can also configure auto scanning of the configuration file by setting the scan=true attribute.

How do I enable debug logs in Logback?

You can now use -Dlogback. debug=true to enable debugging of the logback setup. Unfortunately, there is no way to enable debugging via a System property. You have to use <configuration debug="true"> in the logback.

What is Appender in Logback xml?

Logback Architecture The Logback architecture is comprised of three classes: Logger, Appender, and Layout. A Logger is a context for log messages. This is the class that applications interact with to create log messages. Appenders place log messages in their final destinations.

Does Logback use console-Appender of root to log messages?

With additivity set to false, Logback will not use Console-Appender of root to log messages. Although additivity is a convenient feature and is not intended to trip new users, it can be somewhat confusing. I suggest reviewing the Logback manual on the subject. The complete code of the Logback.xml file is this.

How to configure Logback with Logback XML file?

Logback with logback.xml Configuration Example 1 Project structure. In the following tutorial we will show you how to configure logback with logback.xml file. ... 2 Maven Dependency 3 Example log4j2.xml file. Create a logback.xml file and put it into the resources folder. ... 4 Testing log4j2 configuration 5 Output. ... 6 References. ...

What happens if Logback can't find a configuration file?

This is Logback's default behavior; if it can't find a configuration file, it creates a ConsoleAppender and associates it with the root logger. 6.1. Locating Configuration Information A configuration file can be placed in the classpath and named either logback.xml or logback-test.xml. Here's how Logback will attempt to find configuration data:

What is the default log level set in Logback?

By default, if we do not provide any configuration and add the dependencies in the project, Logback automatically configures the console appender and outputs the logs in the console. The default log level set is DEBUG.


2 Answers

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.

like image 132
Ceki Avatar answered Oct 20 '22 01:10

Ceki


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

like image 29
Jake Collins Avatar answered Oct 20 '22 00:10

Jake Collins