首页 > 解决方案 > 在 logback.xml 中加载外部属性文件值

问题描述

我的属性文件位于“ E:\config\temp\application-serivce.properties”中,并且在该文件中,我将日志文件路径称为“ logging.path=F:\support\conf\logs”。

我在logback-spring.xml下面提到过

<appender name="FILE-ERROR"
        class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${LOG_PATH}/log.${timestamp}.log</file>
</appender>

但是我仍然无法在属性文件中提到的所需路径中创建日志,还有其他方法可以在 logback.xml 中加载属性文件的值。这里我使用的是 spring boot

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.1.RELEASE</version>
    </parent>

标签: spring-bootlogback

解决方案


经过大量谷歌搜索后,我找到了解决方案。我在 logback.xml 和日志文件路径中包含如下内容,我提到过logger_path=F:\support\conf\logs

<property file="E:\config\temp\application-serivce.properties" /> 

<property name="LOG_PATH" value="${logger_path}" />
<appender name="FILE-ERROR"
        class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${LOG_PATH}/log.${timestamp}.log</file>
</appender>

干杯!


推荐阅读