Spring Boot logback 设置默认值

logback Spring Boot About 1,641 words

使用 :- 设置默认值

${A:-B}

如:${java.io.tmpdir:-/tmp}表示取java.io.tmpdir的值,如果没有值设置为/tmp

${A:-${B}}

如:${java.io.tmpdir:-${user.dir}}表示取java.io.tmpdir的值,如果没有值设置为user.dir变量的值。

示例

<?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"/>

    <property name="logPath" value="${java.io.tmpdir:-/tmp}"/>

    <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="CONSOLE"/>
        <appender-ref ref="FILE_APPENDER_ASYNC"/>
    </root>

    <logger name="com.example" level="DEBUG"/>
</configuration>
Views: 3,191 · Posted: 2020-12-23

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh