title: Log4j Programmatically create new file for parallel runs
body: <p>I am at somewhat of a loss. I am trying to create a new log file each time a process runs. The process can run in parallel. When it does, I would like to create a separate log for each process and have the log write to their respective log files. I am struggling with this because whatever is the "last" appender to get created, that is where the files are writing. I don't know how to fix this problem. Enough talk, here is the log4j.properties file.</p>
  
  <pre><code>log4j.rootLogger=DEBUG, CONSOLE
  
  log4j.appender.myappender.encoding=UTF-8
  log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
  log4j.appender.CONSOLE.layout.ConversionPattern=%-5p %x %c - %m%n
  
  # LOGFILE is set to be a File appender using a PatternLayout.
  log4j.appender.LOGFILE=org.apache.log4j.FileAppender
  log4j.appender.LOGFILE.Append=false
  log4j.appender.LOGFILE.Threshold=DEBUG
  log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout
  log4j.appender.LOGFILE.layout.ConversionPattern=%-5p %x %c - %m%n
  </code></pre>
  
  <p>and the code I am using</p>
  
  <pre><code>    Logger rootLogger = Logger.getRootLogger();
      Enumeration appenders = rootLogger.getAllAppenders();
      FileAppender fa = null;
      while(appenders.hasMoreElements())
      {
          Appender currAppender = (Appender) appenders.nextElement();
          if(currAppender instanceof FileAppender)
          {
              fa = (FileAppender) currAppender;
          }
      }
      if(fa != null)
      {
          fa.setFile(logFileName);
          fa.activateOptions();
      }
      else
      {
          log.info("No File Appender found");
      }
  </code></pre>
  
  <p>*Update</p>
  
  <p>So what I am doing is running Quartz. Quartz has a job that can be called concurrently with different params. I would like each separate job run to have its own log file even though they are all calling the same class. </p>
  
  <p>Any help is greatly appreciated.
  Thanks</p>