Logback, encoders instead of patterns.

If you are looking for an example about how to configure logback.xml you may have stumbled upon http://www.mkyong.com/logging/logback-xml-example/ . The post describe a configuration using the “Pattern” tag.

  1. <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
  2.   <layout class="ch.qos.logback.classic.PatternLayout">
  3.     <pattern>
  4.       %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} – %msg%n
  5.     </pattern>
  6.   </layout>
  7. </appender>;

However this configuration has been deprecated in recent logback version, as you can check from the log produced by an application using the latest logback.

10:18:01,156 |-WARN in ch.qos.logback.core.ConsoleAppender[STDOUT] - This appender no longer admits a layout as a sub-component, set an encoder instead.
10:18:01,156 |-WARN in ch.qos.logback.core.ConsoleAppender[STDOUT] - To ensure compatibility, wrapping your layout in LayoutWrappingEncoder.
10:18:01,156 |-WARN in ch.qos.logback.core.ConsoleAppender[STDOUT] - See also http://logback.qos.ch/codes.html#layoutInsteadOfEncoder for details

As the log clearly states, http://logback.qos.ch/codes.html#layoutInsteadOfEncoder gives a quick explanation about how the log should be configured instead.

  1. <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
  2.   <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
  3.     <pattern>%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} – %msg%n</pattern>
  4.   </encoder>
  5. </appender>