title: How to inject active spring profile into logback
body: <p>I'm using a spring boot project.</p>
  
  <p>Environment:</p>
  
  <pre><code>ch.qos.logback:logback-core:jar:1.1.5
  ch.qos.logback:logback-classic:jar:1.1.5
  org.springframework.boot:spring-boot-starter-logging:jar:1.3.3.RELEASE
  </code></pre>
  
  <p>In my project I'm using properties with application.yml (application-dev.yml and application-production.yml)</p>
  
  <p>Since the Logback Spring extension starts before Spring I'm not able to inject the spring.profiles.active into the logback.xml file.</p>
  
  <p>This is a simpler version of my logback.xml file:</p>
  
  <pre><code>&lt;configuration scan="true"&gt;
  
     &lt;property name="LOG_PATH" value="/var/log/" /&gt;
     &lt;property name="APP_NAME" value="xyz" /&gt;
     &lt;property name="PROFILE" value="-${spring.profiles.active}" /&gt;
     &lt;property name="CHARSET" value="utf-8" /&gt;
     &lt;property name="PATTERN" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n" /&gt;
  
     &lt;appender name="APP-FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"&gt;
        &lt;file&gt;${LOG_PATH}${APP_NAME}${PROFILE}.log&lt;/file&gt;
        &lt;encoder&gt;
           &lt;charset&gt;${CHARSET}&lt;/charset&gt;
           &lt;Pattern&gt;${PATTERN}&lt;/Pattern&gt;
        &lt;/encoder&gt;
     &lt;/appender&gt;
  
     &lt;logger name="a.b.c" level="INFO"&gt;
        &lt;appender-ref ref="APP-FILE" /&gt;
     &lt;/logger&gt;
  
     &lt;root level="INFO"&gt;
        &lt;appender-ref ref="APP-FILE"/&gt;
     &lt;/root&gt;
  </code></pre>
  
  <p></p>
  
  <p>The PROFILE I'm looking for is the property <strong>spring.profiles.active</strong>.</p>
  
  <p>My goal is to have a log file on directory <strong>/var/log</strong> the files <strong>xyz-dev</strong> or <strong>xyz-production</strong> but I getting <strong>xyz-spring.profiles.active_IS_UNDEFINED.log</strong> instead of course.</p>
  
  <p>Approaches:</p>
  
  <p>1 - Using a component like:</p>
  
  <pre><code>@Component
  public class InitializationService implements ApplicationListener&lt;ContextRefreshedEvent&gt; {
  
  // inject spring profile active into logback.xml
  
  }
  </code></pre>
  
  <p>is not working of course because the logback Spring extension starts before Spring Boot application.</p>
  
  <p>2 - Using a property on the logback.xml like this</p>
  
  <pre><code>&lt;file&gt;${LOG_PATH}${APP_NAME}${PROFILE}.log&lt;/file&gt;
  </code></pre>
  
  <p>The result is xyz-spring.profiles.active_IS_UNDEFINED.log</p>