问题
How can I get Spring Boot to set a property in my logback.xml based on the profile?
Here's what I tried:
I have an application-default.properties with:
log.dir=/var/log
And an application-development.properties with:
log.dir=target
And I want to pass this into my logback.xml:
<property scope="context" name="logDir" value="${log.dir}" />
Running with development profile -Dspring.profiles.active=development I get logback issue:
RollingFileAppender - Active log file name: log.dir_IS_UNDEFINED/My.log
回答1:
In Spring boot (tested on 1.4.1), I would suggest:
application-default.properties:
logging.file=/var/log/My.log
application-development.properties:
logging.file=/target/My.log
logback-spring.xml:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml"/>
</configuration>
来源:https://stackoverflow.com/questions/37685773/spring-boot-logback-xml-property-depending-on-profile