title: Unable to read properties in logback-spring.xml in Springboot
body: <p>I am trying to create logging functionality using <strong>logback-spring.xml</strong> in my Springboot application,but unable to read the property values(Eg: log.dest.path) in the logback-spring.xml file.</p>
  
  <p><strong>Approach I tried:</strong></p>
  
  <p>I am dynamically loading the property file(YAML) for different environments(dev,stage,prod) based on profiles through <strong>@PropertySource</strong>.
  Profiling is working fine and the right YAML file is loaded (Eg:- application.dev.yml)</p>
  
  <p><strong>logback-spring.xml :</strong></p>
  
  <pre><code>    &lt;configuration debug="true"&gt;
    &lt;property name="PROFILE" value="-${spring.profiles.active}" /&gt;
    &lt;timestamp key="timestamp" datePattern="yyyy-MM-dd" /&gt;
   &lt;springProperty scope="context" name="destination"
          source="log.dest.path" /&gt;
      &lt;springProperty name="fileName" scope="context"
          source="spring.application.name" /&gt;
      &lt;springProfile name="dev"&gt;
          &lt;appender name="FILE" class="ch.qos.logback.core.FileAppender"&gt;
              &lt;file&gt;${destination}/log${PROFILE}/${fileName}_${PROFILE}-${timestamp}.log&lt;/file&gt;
              &lt;encoder&gt;
                  &lt;pattern&gt;%date %level [%thread] %logger{10} [%file : %line] %msg%n&lt;/pattern&gt;
              &lt;/encoder&gt;
          &lt;/appender&gt;
      &lt;/springProfile&gt;
      &lt;springProfile name="production"&gt;
          &lt;appender name="FILE" class="ch.qos.logback.core.FileAppender"&gt;
              &lt;file&gt;${destination}/log${PROFILE}/${fileName}_${PROFILE}-${timestamp}.log&lt;/file&gt;
              &lt;encoder&gt;
                  &lt;pattern&gt;%date %level [%thread] %logger{10} [%file : %line] %msg%n&lt;/pattern&gt;
              &lt;/encoder&gt;
          &lt;/appender&gt;
      &lt;/springProfile&gt;
      &lt;appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"&gt;
          &lt;encoder&gt;
              &lt;pattern&gt;%msg%n&lt;/pattern&gt;
          &lt;/encoder&gt;
      &lt;/appender&gt;
  
      &lt;logger name="com.test" additivity="true"&gt;
          &lt;appender-ref ref="FILE" /&gt;
      &lt;/logger&gt;
  
      &lt;root level="debug"&gt;
          &lt;appender-ref ref="STDOUT" /&gt;
          &lt;appender-ref ref="FILE" /&gt;
      &lt;/root&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p><strong>Config file:</strong></p>
  
  <pre><code>@Configuration
  public class Config {
  
      @Configuration
      @Profile({ "dev", "default" })
      @PropertySource(factory = YamlPropertySourceFactory.class, value = { "classpath:application.dev.yml" })
      static class DevConfig {
      }
  
      @Configuration
      @Profile("stage")
      @PropertySource(factory = YamlPropertySourceFactory.class, value = { "file:////D://file//config.yml" })
      static class StageConfig {
      }
  }
  </code></pre>
  
  <p>I used the @PropertySource approach to load proeprty files because,property files are  externally placed in one of the environment.</p>
  
  <p>When the application starts the log file is not getting created in the specified path provided in the properties file,instead a  folder with <strong>destination_IS_UNDEFINED</strong> is created in the project root directory.</p>
  
  <p>But I am getting the environment properties through below code:</p>
  
  <pre><code>@SpringBootApplication
  public class ProfileProject extends SpringBootServletInitializer {
  
      public static void main(String[] args) {
          ConfigurableApplicationContext configurableApplicationContext = new SpringApplicationBuilder(
                  ProfileProject.class).sources(ProfileProject.class).run(args);
          ConfigurableEnvironment environment = configurableApplicationContext.getEnvironment();      
          System.out.println("Env variables Log Dest path ----&gt; : " + environment.getProperty("log.dest.path"));
  
      }
  
  }
  </code></pre>
  
  <p><strong>application.dev.yml:</strong> - sample</p>
  
  <pre><code>server:
    port: 7999
  app:
    name: DEVELOPMENT
  spring:
    application:
      name: ProfileDEV
  log:
    dest:
      path: D:\development
  logging:
   config: classpath:logback-spring.xml
  </code></pre>
  
  <p><strong>Approach Worked :</strong> </p>
  
  <p>Have all the profile level properties to respective yaml file(Eg:-application.{env}.yml) and have a application.properties file where properties required for logback-spring.xml are placed.</p>
  
  <p><strong>Note:-</strong></p>
  
  <p>SpringBoot- logging , doesn't wait for the @ProperySource to finish configuration. As a result the property file loaded through this approach will not be read by logback-spring.xml but will read application.properties.</p>