title: Log4j2 system property written as a file
body: <p>I use the following log4j2 configuration:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;Configuration status="WARN"&gt;
      &lt;Appenders&gt;
          &lt;Console name="Console" target="SYSTEM_OUT"&gt;
              &lt;PatternLayout pattern="%d{HH:mm:ss.SSS} %-5.5level %-60.60logger - %msg%n" /&gt;
              &lt;Filters&gt;
                  &lt;ThresholdFilter level="info" onMatch="ACCEPT"
                      onMismatch="DENY" /&gt;
              &lt;/Filters&gt;
          &lt;/Console&gt;
          &lt;RollingFile name="RollingFile"
              fileName="${sys:log.file}"
              filePattern="${sys:log.parent.path}\$${date:yyyy-MM}\${sys:log.file.name}-%d{MM-dd-yyyy}-%i.log.gz"&gt;
              &lt;PatternLayout&gt;
                  &lt;Pattern&gt;
                      %d{yyy-MM-dd HH:mm:ss.SSS} [%30.30t]%-10.10level%-60.60logger - %msg%n
                  &lt;/Pattern&gt;
              &lt;/PatternLayout&gt;
              &lt;Policies&gt;
                  &lt;TimeBasedTriggeringPolicy /&gt;
                  &lt;SizeBasedTriggeringPolicy size="60 MB" /&gt;
              &lt;/Policies&gt;
          &lt;/RollingFile&gt;
      &lt;/Appenders&gt;
      &lt;Loggers&gt;
          &lt;Root level="trace"&gt;
              &lt;AppenderRef ref="RollingFile" /&gt;
              &lt;AppenderRef ref="Console" /&gt;
          &lt;/Root&gt;
      &lt;/Loggers&gt;
  &lt;/Configuration&gt;
  </code></pre>
  
  <p>The system parameters are set when the file location is passed as a command line parameter and then the function reconfigureLog() sets the properties</p>
  
  <pre><code>public static void reconfigureLog(String logPath)
      {
          File logFile = new File(logPath);
          System.setProperty("log.file", logPath);
          System.setProperty("log.parent.path", logFile.getParent());
          System.setProperty("log.file.name", FilenameUtils.getBaseName(logFile.getName()));
  
          org.apache.logging.log4j.core.Logger rootLogger = (org.apache.logging.log4j.core.Logger) LogManager
                  .getRootLogger();
          LoggerContext context = rootLogger.getContext();
          context.reconfigure();
      }
  </code></pre>
  
  <p>This is the sample usage of the scenario where I read the parameters from the command line and then set it later.</p>
  
  <pre><code>if (cmd.hasOption("logFile"))
          {
              String logPath = cmd.getOptionValue("logFile");
              Utility.reconfigureLog(logPath);
              logger = LogManager.getLogger(Test.class);
          }
  </code></pre>
  
  <p>Every class has a static logger initialization like this:</p>
  
  <pre><code>private final static Logger logger = LogManager.getLogger(Connector.class);
  </code></pre>
  
  <p>The issue is when I run the application, <code>${sys.log.file}</code> is being created and then the corresponding log file from the parameters is created. Prodding through the parameters it seems that the parameter fileName under the RolllingFile is automatically added. </p>
  
  <p>The debug log for log4j2 is:</p>
  
  <pre><code>2015-12-03 11:07:19,204 main DEBUG Calling createAppender on class org.apache.logging.log4j.core.appender.RollingFileAppender for element RollingFile with params(fileName="${sys:log.file}", filePattern="${sys:log.parent.path}\${date:yyyy-MM}\${sys:log.file.name}-%d{MM-dd-yyyy}-%i.log.gz", append="null", name="RollingFile", bufferedIO="null", bufferSize="null", immediateFlush="null", Policies(CompositeTriggeringPolicy(policies=[TimeBasedTriggeringPolicy(nextRolloverMillis=0, interval=1, modulate=false), SizeBasedTriggeringPolicy(size=62914560)])), null, PatternLayout(%d{yyy-MM-dd HH:mm:ss.SSS} [%30.30t]%-10.10level%-60.60logger - %msg%n), null, ignoreExceptions="null", advertise="null", advertiseURI="null", Configuration(&lt;path&gt;\Connector\target\classes\log4j2.xml))
  2015-12-03 11:07:19,207 main DEBUG Starting RollingFileManager ${sys:log.file}
  </code></pre>
  
  <p>It can be seen that the system parameter is literally picked instead of substitution. I need to avoid the early initialization and start this loading only after calling the reconfigureLog method.
  How can I avoid <code>${sys.log.file}</code> being created when I can use system parameters as part of my application?</p>