title: How to set log4j path on startup in web app?
body: <p>I have a log4j2.xml configuration file that should get the logging path dynamically set during startup of the web application by java code.</p>
  <h1>log4j2.xml:</h1>
  <pre><code>&lt;Properties&gt;
      &lt;property name=&quot;path&quot;&gt;{web:attr.logpath}&lt;/property&gt;
  &lt;/Properties&gt;
  </code></pre>
  <p>Therefore I have the following configuration file:</p>
  <pre><code>@Configuration
  @Order(Ordered.HIGHEST_PRECEDENCE)
  public class LogConfig extends SpringBootServletInitializer {
      @Override
      public void onStartup(ServletContext servletContext) throws ServletException {
          servletContext.addListener(Log4jConfigListener.class);
          servletContext.setAttribute(&quot;logpath&quot;, &quot;d:/testpath&quot;);
          super.onStartup(servletContext);
      }
  }
  </code></pre>
  <p>Problem: When <code>onStartup()</code> is entered, the log4j initialization is already over and I get the message that log4j path is invalid.</p>
  <p>How can I delay the log4j initialization after the attributes have been set?</p>