title: Log4j config - different logs to different files
body: <p>This might be a very easy question for some, but personally I find Log4j config to be nightmarishly difficult and that learning to perform brain surgery might be less challenging.</p>
  
  <p>I am trying to lave multiple loggers logging into different files.
  Here is what I have  in my log4j.properties file:</p>
  
  <pre><code># Root logger option
  log4j.rootLogger=INFO, file, admin
  
  # Direct log messages to a log file
  log4j.appender.file=org.apache.log4j.RollingFileAppender
  log4j.appender.file.File=/home/nick/logging/file.log
  log4j.appender.file.MaxFileSize=1MB
  log4j.appender.file.MaxBackupIndex=1
  log4j.appender.file.layout=org.apache.log4j.PatternLayout
  log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1} - %m%n
  
  log4j.appender.admin=org.apache.log4j.RollingFileAppender
  log4j.appender.admin.File=/home/nick/logging/admin.log
  log4j.appender.admin.MaxFileSize=1MB
  log4j.appender.admin.MaxBackupIndex=1
  log4j.appender.admin.layout=org.apache.log4j.PatternLayout
  log4j.appender.admin.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1} - %m%n
  </code></pre>
  
  <p>And here is my (very simple) Java app used to test the config:</p>
  
  <pre><code>public static void main(String[] args) throws Exception {
  
      Properties resource = new Properties();
      InputStream in = new FileInputStream("/home/nick/logging/log4j.properties");
      resource.load(in);
      PropertyConfigurator.configure(resource);
  
      Logger admin = Logger.getLogger("admin");
      Logger file = Logger.getLogger("file");
  
      admin.info("hello admin");
      file.info("hello file");
  }
  </code></pre>
  
  <p>I have 2 problems:</p>
  
  <p>One problem I always get an exception in the line <code>PropertyConfigurator.configure(resource);</code>:</p>
  
  <pre><code>java.io.FileNotFoundException: /home/nick/logging (Is a directory)
   at java.io.FileOutputStream.open(Native Method)
   at java.io.FileOutputStream.&lt;init&gt;(FileOutputStream.java:212)
   at java.io.FileOutputStream.&lt;init&gt;(FileOutputStream.java:136)
   at org.apache.log4j.FileAppender.setFile(FileAppender.java:289)
   at org.apache.log4j.RollingFileAppender.setFile(RollingFileAppender.java:167)
   at org.apache.log4j.FileAppender.activateOptions(FileAppender.java:163)
   at org.apache.log4j.config.PropertySetter.activate(PropertySetter.java:256)
  </code></pre>
  
  <p>The 2nd problem is that both messages are written to both logs. Here is the <strong>actual</strong> result:</p>
  
  <p>File admin:log:</p>
  
  <pre><code>2014-04-27 11:55:30 INFO  admin - hello admin
  2014-04-27 11:55:30 INFO  file - hello file
  </code></pre>
  
  <p>File file.log:</p>
  
  <pre><code>2014-04-27 11:55:30 INFO  admin - hello admin
  2014-04-27 11:55:30 INFO  file - hello file
  </code></pre>
  
  <p>Here is the <strong>required</strong> result:</p>
  
  <p>File admin:log:</p>
  
  <pre><code>2014-04-27 11:55:30 INFO  admin - hello admin
  </code></pre>
  
  <p>File file.log:</p>
  
  <pre><code>2014-04-27 11:55:30 INFO  file - hello file
  </code></pre>
  
  <p>What is causing the exception, and how can I achieve the required result?</p>