使用Spring Boot 1.5.x应用程序覆盖logback.xml

时间:2018-07-17 09:41:32

标签: spring spring-boot logback

我正在尝试在Spring Boot(1.5.x)应用程序中写回日志配置。

问题- 问题在于它不会创建任何日志文件/文件夹(或者可能不在正确的路径中)。

代码-

logback.xml

<configuration>
    <include resource="org/springframework/boot/logging/logback/base.xml"/>
    <property name="LOG_PATH" value="logs" />
    <appender name="ROLLING" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${LOG_PATH}/mylog.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <!-- rollover daily -->
            <fileNamePattern>${LOG_PATH}/mylog-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
            <!-- each file should be at most 100MB, keep 60 days worth of history, but at most 20GB -->
            <maxFileSize>100MB</maxFileSize>
            <maxHistory>60</maxHistory>
            <totalSizeCap>20GB</totalSizeCap>
        </rollingPolicy>
        <encoder>
            <pattern>%msg%n</pattern>
        </encoder>
    </appender>

</configuration>

2 个答案:

答案 0 :(得分:0)

</configuration>之前在末尾添加

<root level="INFO">
   <appender-ref ref="ROLLING"/>
</root>

答案 1 :(得分:0)

在运行应用程序时要么传递LOG_PATH while变量,要么在如下所示的同一文件中进行定义(type_value LIKE ALL ('%AZ=jh-ee60;%','%XCA=6E16;%') OR type_value LIKE ALL ('%AZ=jh-ee30;%','%XCA=TO-IO;%')) (type_value LIKE ALL ('%Q=3WE.5_%_WW21_;%')) (type_value LIKE ALL ('%system=V378.63;%','%s_num=KMSS;%') OR type_value LIKE ALL ('%system=D885.13;%','%s_num=UASS;%') OR type_value LIKE ALL ('%system=DV5.1;%','%s_num=R;%') OR type_value LIKE ALL ('%system=DV25.1;%','%s_num=W;%'))

还要添加 <property name="LOG_PATH" value="logs"/>