简体   繁体   中英

spring-boot logback.xml property depending on profile

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

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM