java 使用 application.properties 在 Spring Boot 中外部化 logback.xml 的位置

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32944356/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 21:00:08  来源:igfitidea点击:

Externalized the location of logback.xml in Spring Boot using application.properties

javaspringjakarta-eespring-bootlogback

提问by richersoon

How can I customized the location of logback.xml in Spring Boot using application.properties?

如何使用 application.properties 在 Spring Boot 中自定义 logback.xml 的位置?

I tried below but is not working.

我在下面试过,但没有用。

application.properties

应用程序属性

logging.config = /home/dev-01/Documents/logback.xml

It is working if the logback.xml is located in the resource folder, but not working if it is located outside the project.

如果 logback.xml 位于资源文件夹中,则它可以工作,但如果它位于项目之外,则无法工作。

It is also working if the I supply as environment variable like

如果我作为环境变量提供,它也可以工作

-Dlogging.config=/home/dev-01/Documents/logback.xml

回答by luboskrnac

Below construct worked for me (but I used relative path instead of absolute):

下面的构造对我有用(但我使用了相对路径而不是绝对路径):

logging.config=file:/home/dev-01/Documents/logback.xml