title: Logback - set log file name programmatically
body: <p>I am using logback, and I am trying to set the log file name programmatically within my Java program (similar to <a href="https://stackoverflow.com/questions/3803184/setting-logback-appender-path-programmatically">Setting Logback Appender path programmatically</a>), and I tried to adapt that solution as follows:</p>
  
  <p>In logback-test.xml:</p>
  
  <pre><code>&lt;appender name="FILE" class="ch.qos.logback.core.FileAppender"&gt;
    &lt;file&gt;log/${log_file_name}.log&lt;/file&gt;
    ...
  </code></pre>
  
  <p>And then again in my Java program:</p>
  
  <pre><code>String logFileName = "" + System.currentTimeMillis(); // just for example
  System.setProperty("log_file_name", logFileName);
  
  LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
  ContextInitializer ci = new ContextInitializer(lc);
  lc.reset();
  try
  {
      // I prefer autoConfig() over JoranConfigurator.doConfigure() so I
      // wouldn't need to find the file myself.
      ci.autoConfig();
  }
  catch (JoranException e)
  {
      // StatusPrinter will try to log this
      e.printStackTrace();
  }
  StatusPrinter.printInCaseOfErrorsOrWarnings(lc);
  </code></pre>
  
  <p>However the result is two logs, one full and named as I wanted, e.g., "1319041145343.log", and the other is empty and named "log_file_name_IS_UNDEFINED.log". How do I stop this other empty log file from being created?</p>