logback日志打印两遍

logback一条日志重复打印多次的解决办法,将 additivity设置为false。

配置节点:

 <logger name="chapters.configuration.Foo" additivity="false">

logback.xml

<configuration>
 <appender name="FILE" class="ch.qos.logback.core.FileAppender">
  <file>foo.log</file>
  <encoder>
   <pattern>%date %level [%thread] %logger{10} [%file : %line] %msg%n</pattern>
  </encoder>
 </appender>

 <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
  <encoder>
   <pattern>%msg%n</pattern>
  </encoder>
 </appender>

 <logger name="chapters.configuration.Foo" additivity="false">
  <appender-ref ref="FILE" />
 </logger>

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

具体配置参考:

http://logback.qos.ch/manual/configuration.html