title: One logfile per run with log4j
body: <p>How do you configure log4j.properties to have exactly one logfile per run of an app.
  I've read that you should use a timestamp in the filename but that will create many files per run as time goes by.</p>
  
  <p>I tried DailyRollingFileAppender and RollingFileAppender but can't find a way to configure exctly one log per run. The log should not be broken into multiple logs and it shouldn't be truncated and files of old runs should be preserved.</p>
  
  <p>Each class has a static org.slf4j.Logger for it's own class name:</p>
  
  <pre><code>private static final Logger log = LoggerFactory.getLogger(Foo.class);
  </code></pre>
  
  <p>This is my current log4j.properties</p>
  
  <pre><code>log4j.rootLogger=error, RootAppender, RootErrorAppender
  
  #log4j.logger.com.example=info, qspaBackendAppender, stderr
  log4j.logger.com.example=info, qspaBackendAppender
  log4j.additivity.com.example=true
  
  #log4j.logger.com.example.util=trace, qspaBackendAppender, stderr
  #log4j.additivity.com.example.util=true
  
  log4j.appender.qspaBackendAppender=org.apache.log4j.DailyRollingFileAppender
  log4j.appender.qspaBackendAppender.file=logs/qspaBackend.log
  log4j.appender.qspaBackendAppender.layout=org.apache.log4j.PatternLayout
  log4j.appender.qspaBackendAppender.layout.ConversionPattern=&lt;%d{yyyy-MM-dd HH:mm:ss}&gt; %-5p : %C{1} %c{2} : %m%n
  
  log4j.appender.stderr=org.apache.log4j.ConsoleAppender
  log4j.appender.stderr.Target=System.err
  log4j.appender.stderr.layout=org.apache.log4j.PatternLayout
  log4j.appender.stderr.layout.ConversionPattern=%-5p %c{1}:%L - %m%n
  
  log4j.appender.RootAppender=org.apache.log4j.RollingFileAppender
  log4j.appender.RootAppender.file=logs/root.log
  log4j.appender.RootAppender.layout=org.apache.log4j.PatternLayout
  log4j.appender.RootAppender.layout.ConversionPattern=&lt;%d{yyyy-MM-dd HH:mm:ss}&gt; %-5p : %C{1} %c{2} : %m%n
  
  log4j.appender.RootErrorAppender=org.apache.log4j.RollingFileAppender
  log4j.appender.RootErrorAppender.file=logs/rootError.log
  log4j.appender.RootErrorAppender.layout=org.apache.log4j.PatternLayout
  log4j.appender.RootErrorAppender.layout.ConversionPattern=&lt;%d{yyyy-MM-dd HH:mm:ss}&gt; %-5p : %C{1} %c{2} : %m%n
  log4j.appender.RootErrorAppender.threshold=error
  </code></pre>