Spring Boot logback springProperty 设置默认值

2021/11/9 6:10:21

本文主要是介绍Spring Boot logback springProperty 设置默认值,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

springProperty

当没有读取到source字段中设置的log.path值时,设置为defaultValue字段中的${user.dir}/logs变量值。

<springProperty scope="context" name="logPath" source="log.path" defaultValue="${user.dir}/logs"/>

示例

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

    <springProperty scope="context" name="logPath" source="log.path" defaultValue="${user.dir}/logs"/>

    <appender name="FILE_APPENDER" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <File>${logPath}/log-info.log</File>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <FileNamePattern>${logPath}/history-log-%d{yyyy-MM-dd}.zip</FileNamePattern>
            <maxHistory>5</maxHistory>
        </rollingPolicy>
        <encoder>
            <Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{35} - %msg %n</Pattern>
        </encoder>
    </appender>

    <appender name="FILE_APPENDER_ASYNC" class="ch.qos.logback.classic.AsyncAppender">
        <discardingThreshold>0</discardingThreshold>
        <queueSize>12000</queueSize>
        <neverBlock>true</neverBlock>
        <appender-ref ref="FILE_APPENDER"/>
    </appender>

    <root level="INFO">
        <appender-ref ref="FILE_APPENDER_ASYNC"/>
        <appender-ref ref="CONSOLE"/>
    </root>

    <logger name="com.example" level="INFO"/>
</configuration>
阅读 1494 · 发布于 2020-12-24

这篇关于Spring Boot logback springProperty 设置默认值的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程