How to prevent logback from outputting its own status at the start of every log when using a layout

If you set the debug attribute of the configuration element to true, you will get all status information to the console. If this is your problem, just set it to false or remove it.

If you have any configuration problems of level WARN or above, you will also get all status information logged to the console (including messages of level INFO). The best solution to this problem is to fix the problem (in your case replace the <layout> element with an <encoder> element).

If you for some reason cannot fix the problem, but want to remove the status-information from the console, you can instead configure an alternative StatusListener. Use the NopStatusListener to completely remove the status-information:

<configuration>
  <statusListener class="ch.qos.logback.core.status.NopStatusListener" />
  <!-- etc -->
</configuration>

As described in the docs, if warnings or errors occur during the parsing of the configuration file, logback will automatically print status data on the console.

Follow http://logback.qos.ch/codes.html#layoutInsteadOfEncoder i.e. the link mentioned by logback in its warning message. Once you follow the steps mentioned therein, that is, if you replace <layout> element with <encoder>, logback will stop printing messages on the console.


Ceki answer is correct:

(...)if warnings or errors occur during the parsing of the configuration file, logback will automatically print status data on the console.

Once you get it right, there won't be any pollution in the first lines of your log anymore.

As of March 2015, in Logback 1.1.2, you need to use <encoder> sub-component - <layout> is now deprecated and if use it, error messages will appear. You cannot control this, it´s Logback default behavior.

Some internal classes have been renamed too, and even the examples in their manual page are outdated!

Here is the code snippet from their Errors Code Help page, which has the correct way to config the logger. This fixed the issue completely in my project. http://logback.qos.ch/codes.html#layoutInsteadOfEncoder

<appender name="FILE" class="ch.qos.logback.core.FileAppender">
  <file>testFile.log</file>
  ...
  <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
    <pattern>%msg%n</pattern>
  </encoder>
</appender>

I realized Steve found the fix but he didn't mention it on the thread. In case if any other person hit the same issue here is the fix.

Replace "<layout>" elements with "<encoder>..</encoder>"

The culprit is: <layout class="ch.qos.logback.classic.PatternLayout">