How to configure rolling file appender within Spring Boot's application.yml

后端 未结 7 722
[愿得一人]
[愿得一人] 2020-12-01 17:35

Is is possible to configure a daily file appender within the application.yml of a Spring Boot application?

i.e. filenamePattern: myfile.%d{yyyy-MM-dd-HH-mm-ss}.log

相关标签:
7条回答
  • 2020-12-01 18:29

    To override the default file appender and change it to daily rollover, you could use a logback-spring.xml looking like this:

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
        <include resource="org/springframework/boot/logging/logback/defaults.xml"/>
        <property name="LOG_FILE" value="${LOG_FILE:-${LOG_PATH:-${LOG_TEMP:-${java.io.tmpdir:-/tmp}}/}spring.log}"/>
        <include resource="org/springframework/boot/logging/logback/console-appender.xml"/>
    
        <appender name="ROLLING-FILE"
                  class="ch.qos.logback.core.rolling.RollingFileAppender">
            <encoder>
                <pattern>${FILE_LOG_PATTERN}</pattern>
            </encoder>
            <file>${LOG_FILE}</file>
            <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
                <!-- daily rollover -->
                <fileNamePattern>${LOG_FILE}.%d{yyyy-MM-dd}.log</fileNamePattern>
            </rollingPolicy>
        </appender>
    
        <root level="INFO">
            <appender-ref ref="CONSOLE"/>
            <appender-ref ref="ROLLING-FILE"/>
        </root>
    
    </configuration>
    
    0 讨论(0)
提交回复
热议问题