title: Accessing environment variable from log4j2.xml
body: <p>I am developing a Spring Boot web application. I am trying to access an environment variable from Websphere server in my log4j2.xml configuration. But somehow it's not working.</p>
  
  <p>Environment variable is set in WAS under the below path - </p>
  
  <p>Application servers > server001 > Process definition > Java Virtual Machine > Custom properties</p>
  
  <p><a href="https://i.stack.imgur.com/uJzhj.png" rel="noreferrer">environment variable image</a></p>
  
  <p>My log4j2.xml configuration is as follows - </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;Appenders&gt;
   
          &lt;RollingFile name="RollingFile"
              fileName="$${env:environment}/apps/was/logs/app-logs.log"
              filePattern="$${env:environment}/apps/was/logs/$${date:yyyy-MM}/app-logs-%d{-dd-MMMM-yyyy}-%i.log.gz"&gt;
              &lt;PatternLayout&gt;
                  &lt;pattern&gt;%d %p %C{1.} [%t] %m%n&lt;/pattern&gt;
              &lt;/PatternLayout&gt;
              &lt;Policies&gt;
                  &lt;OnStartupTriggeringPolicy /&gt;
                  &lt;SizeBasedTriggeringPolicy
                      size="10 MB" /&gt;
                  &lt;TimeBasedTriggeringPolicy /&gt;
              &lt;/Policies&gt;
          &lt;/RollingFile&gt;
  &lt;/Appenders&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>I have tried to get the environment variable using $${env:environment} / ${env:environment}/ ${environment}. Nothing is working working. It's not able to fetch the environment variable. So it's crating a folder named "${env:environment}" / ${environment} instead of "DVL".</p>
  
  <p>From java I can able to access my environment variable without any issue - </p>
  
  <p>System.getProperty("environment") ==> DVL</p>
  
  <p>Please Help.</p>