简体   繁体   中英

Disable log archival Spring boot log configuration

When I use the below configuration for logging in a spring boot application, after a day is end the current log file is immediately archived.

logging:
  level:
    com.example.com: DEBUG
  file:
    path: /home/user/logs
    max-history: 7

I want to keep the log files for days without archiving them in the folder, Is it possible to do that, Please help me on this.

You should add a logback file to change the configuration of your logs, something like this:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
 
    <appender name="RollingFile"
        class="ch.qos.logback.core.rolling.RollingFileAppender">
         
        <rollingPolicy
            class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <!-- rollover daily and when the file reaches 10 MegaBytes -->
            <fileNamePattern>$logs/archived/spring-boot-logger-%d{yyyy-MM-dd}.%i.log
            </fileNamePattern>
            <timeBasedFileNamingAndTriggeringPolicy
                class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <maxFileSize>10MB</maxFileSize>
            </timeBasedFileNamingAndTriggeringPolicy>
        </rollingPolicy>
    </appender>
    
    <!-- LOG everything at INFO level -->
    <root level="info">
        <appender-ref ref="RollingFile" />
        
    </root>
 
</configuration>

You can check here https://www.baeldung.com/spring-boot-logging for more possible configurations.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM