spring-boot logback.xml属性取决于配置文件 [英] spring-boot logback.xml property depending on profile

查看:277
本文介绍了spring-boot logback.xml属性取决于配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何让Spring Boot根据配置文件在我的logback.xml中设置属性?

How can I get Spring Boot to set a property in my logback.xml based on the profile?

这是我尝试过的:

我有一个application-default.properties,其中:

log.dir=/var/log

还有一个application-development.properties,具有:

log.dir=target

我想将其传递给我的logback.xml:

<property scope="context" name="logDir" value="${log.dir}" />

使用开发配置文件-Dspring.profiles.active=development运行时,出现logback问题:

Running with development profile -Dspring.profiles.active=development I get logback issue:

RollingFileAppender - Active log file name: log.dir_IS_UNDEFINED/My.log

推荐答案

在Spring引导中(在1.4.1上进行测试),我建议:

In Spring boot (tested on 1.4.1), I would suggest:

application-default.properties:

application-default.properties:

logging.file=/var/log/My.log

application-development.properties:

application-development.properties:

logging.file=/target/My.log

logback-spring.xml:

logback-spring.xml:

<?xml version="1.0" encoding="UTF-8"?>
  <configuration>
     <include resource="org/springframework/boot/logging/logback/base.xml"/>
  </configuration>

这篇关于spring-boot logback.xml属性取决于配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆