I'm using Spring Boot 1.3.0.RC1 through spring-cloud Brixton.M2 and have been unable to pull spring boot properties into logback.xml as implied by this feature checkin Support springProperty in logback configurations
I'm using .yml files and want to pull application name out of bootstrap.yml or application.yml.
<springProperty scope="context" name="myappName" source="spring.application.name"/>
<appender name="logFileAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:1.3.0.RC1:compile
[INFO] | +- org.springframework.boot:spring-boot-starter:jar:1.3.0.RC1:compile
[INFO] | | +- org.springframework.boot:spring-boot:jar:1.3.0.RC1:compile
[INFO] | | +- org.springframework.boot:spring-boot-autoconfigure:jar:1.3.0.RC1:compile
[INFO] | | +- org.springframework.boot:spring-boot-starter-logging:jar:1.3.0.RC1:compile
[INFO] | | | +- ch.qos.logback:logback-classic:jar:1.1.3:compile
[INFO] | | | | \- ch.qos.logback:logback-core:jar:1.1.3:compile
[INFO] | | | +- org.slf4j:jcl-over-slf4j:jar:1.7.12:compile
[INFO] | | | +- org.slf4j:jul-to-slf4j:jar:1.7.12:compile
[INFO] | | | \- org.slf4j:log4j-over-slf4j:jar:1.7.12:compile
[INFO] | | \- org.yaml:snakeyaml:jar:1.16:runtime
To provide my analysis and a solution for future readers... I tried with
spring.application.name values in
application.properties but none worked. I thought it was because I used
logback.xml, but converting to
logback-spring.xml resulted in no change. Looking at the code committed here, pulling the values via
this.environment.getProperty(source) is dependent on when the property sources are loaded vs when the
logback-spring.xml file is interpreted. Not sure why Dave Syer was able to get it to work but my .xml variable was populated before local property sources are added to the environment.
The value is populated within the .xml file if I set it via SpringApplication.setDefaultProperties(). Hence that is the route I took.
SpringApplicationRunListener.started(), I read in bootstrap.yml (where I required spring.application.name for all framework users) via
service.log.namein a HashMap based off the value
SpringApplication.setDefaultProperties()with that HashMap
I admit this is not a perfect solution, but one that works for now and will likely continue to work for future releases of springBoot. I am open to further ideas but wanted to provide a solution that worked for others that are having the same experience.