SpringBoot在logback.xml中讀取application.properties中配置的日志路徑
https://blog.csdn.net/xiaoxiao_su123/article/details/106523713
問題描述
在springboot項目中使用logback記錄日志,在logback.xml中配置日志存儲位置時讀取application.properties中配置的路徑,在 logback.xml中配置引用如下:
<property name="log.path" value="${path.log}"/>
發現讀取不到
原因分析
因為logback.xml的加載順序早於springboot的application.yml (或application.properties) 配置文件。當然讀不到application.yml(或application.properties)文件中的值了。
解決方案
1. 需要通過springProperty標簽來引用:<springProperty scope="context" name="log.path" source="path.log"/>
這里的name和上面property標簽一樣不多說,source其實就是上面的value,只不過要注意:千萬不要加${}
2. 如果還是讀取不到,請把你的logback.xml配置文件名,改為:logback-spring.xml就可以了。
參考文章
原文鏈接:https://www.cnblogs.com/xingfudexu/p/10374639.html