spring-boot logback.xml property depending on profile

℡╲_俬逩灬. 提交于 2020-01-06 03:25:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!