Stack Exchange
Unable to read properties in logback-spring.xml in Springboot
I am trying to create logging functionality using logback-spring.xml in my Springboot application,but unable to read the property values(Eg: log.dest.path) in the logback-spring.xml file.
Approach I tried:
I am dynamically loading the property file(YAML) for different environments(dev,stage,prod) based on profiles through @PropertySource.
Profiling is working fine and the right YAML file is loaded (Eg:- application.dev.yml)
logback-spring.xml :
    <configuration debug="true">
  <property name="PROFILE" value="-${spring.profiles.active}" />
  <timestamp key="timestamp" datePattern="yyyy-MM-dd" />
 <springProperty scope="context" name="destination"
        source="log.dest.path" />
    <springProperty name="fileName" scope="context"
        source="spring.application.name" />
    <springProfile name="dev">
        <appender name="FILE" class="ch.qos.logback.core.FileAppender">
            <file>${destination}/log${PROFILE}/${fileName}_${PROFILE}-${timestamp}.log</file>
            <encoder>
                <pattern>%date %level [%thread] %logger{10} [%file : %line] %msg%n</pattern>
            </encoder>
        </appender>
    </springProfile>
    <springProfile name="production">
        <appender name="FILE" class="ch.qos.logback.core.FileAppender">
            <file>${destination}/log${PROFILE}/${fileName}_${PROFILE}-${timestamp}.log</file>
            <encoder>
                <pattern>%date %level [%thread] %logger{10} [%file : %line] %msg%n</pattern>
            </encoder>
        </appender>
    </springProfile>
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%msg%n</pattern>
        </encoder>
    </appender>

    <logger name="com.test" additivity="true">
        <appender-ref ref="FILE" />
    </logger>

    <root level="debug">
        <appender-ref ref="STDOUT" />
        <appender-ref ref="FILE" />
    </root>
</configuration>

Config file:
@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 {
    }
}

I used the @PropertySource approach to load proeprty files because,property files are  externally placed in one of the environment.
When the application starts the log file is not getting created in the specified path provided in the properties file,instead a  folder with destination_IS_UNDEFINED is created in the project root directory.
But I am getting the environment properties through below 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 ----> : " + environment.getProperty("log.dest.path"));

    }

}

application.dev.yml: - sample
server:
  port: 7999
app:
  name: DEVELOPMENT
spring:
  application:
    name: ProfileDEV
log:
  dest:
    path: D:\development
logging:
 config: classpath:logback-spring.xml

Approach Worked : 
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.
Note:-
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.

share application properties file and project explorer

Shared the file content.The logback-spring.xml , appliaction.dev.yml are directly under resource folder

I was able to get it work post following the link- https://github.com/spring-projects/spring-boot/issues/6219#issuecomment-228335328 .Now I am using Springprofilesin logback-spring.xml to get more flexibility

you can use the scope attribute with context value to access the property from the Environment.
you can also set the defaultValue attribute. 
For example:
<springProperty scope="context" name="destination" 
                source="log.dest.path" defaultValue="\temp"/>

if logback-spring.xml not loaded add a property in the application.properties file.
logging.config: classpath:./logback-spring.xml


I tried adding the attribute  scope="context" , not reading the property value.But  I am getting the environment values through above code(Edit)

have you check logback-spring.xml loaded or not?

The logback-spring.xml is loaded and can trace logs,but property is not read in file.I have set 
