title: Log4j : Multiple loggers, levels and appenders
body: <p>I am having trouble with duplicate log messages when writing to multiple log files using log4j.</p>
  
  <p>At present I am trying to log <code>INFO</code> level data (and upwards) for the specific logger named <strong>foobar</strong> in my <code>foo.log</code> file and then all <code>WARN</code> level log messages (and upwards) for <strong>all loggers</strong> in the <code>bar.log</code> file.</p>
  
  <p>As a result of this, duplicate log messages were written to the <code>foo.log</code> file (each line was logged twice) and after some quick research I found that the suggestion to fix this was to add <code>log4j.additivity.foobar=false</code> to my properties file.</p>
  
  <p>The problem with this is that although it stops duplicate lines, the <code>WARN</code> message from the <strong>foobar</strong> logger are never written to the <code>bar.log</code> file.</p>
  
  <p><strong>My log4j properties file is as follows:</strong></p>
  
  <pre><code>log4j.rootLogger = WARN, FOO, BAR
  log4j.logger.foobar = INFO, FOO
  log4j.additivity.foobar = false
  
  log4j.appender.FOO = org.apache.log4j.RollingFileAppender
  log4j.appender.FOO.layout = org.apache.log4j.PatternLayout
  log4j.appender.FOO.layout.ConversionPattern = %d{ISO8601} %-5p %c ~ %m%n
  log4j.appender.FOO.File = foo.log
  
  log4j.appender.BAR = org.apache.log4j.RollingFileAppender
  log4j.appender.BAR.layout = org.apache.log4j.PatternLayout
  log4j.appender.BAR.layout.ConversionPattern = %d{ISO8601} %-5p %c ~ %m%n
  log4j.appender.BAR.File = bar.log
  </code></pre>
  
  <p>Does anyone know how I can write the log messages to both log files (as it was doing before I started setting the <code>additivity</code> property) and still prevent the duplicate log messages?</p>
  
  <p><em>Please note, this is a simplified summary of the problem. In the real world scenario there are multiple loggers and more than two log files</em></p>