2

我在配置 logback-spring.xml 文件的时候卡住了。问题是我的旧存档文件没有被删除,但是 Spring boot 可以识别 xml 文件。当我更改 maxFileSize 参数时,我可以看到更改。只有 maxHistory 没有正确反应:当我将其设置为 90 天时,它会随机删除 3-4 个文件。我有大约 200 个存档文件(从 2018 年到 2019 年)。提前致谢。

我将文件名从 logback.xml 重命名为 logback-spring.xml,但没有任何变化。

--- logback-spring.xml 


<?xml version="1.0" encoding="UTF-8"?>
<configuration>

<property name="LOG_PATH" value="log/" />

<appender name="STDOUT"
class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>
    %d{dd.MM.yyyy HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n
</Pattern>
</layout>
</appender>

<appender name="FILE"
    class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>${LOG_PATH}spring-boot.log</file>
    <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
        <Pattern>
            %d{dd.MM.yyyy HH:mm:ss} [%thread] %-5level %logger{36} - 
%msg%n
        </Pattern>
    </encoder>

    <rollingPolicy 
class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
        <!-- rollover daily -->
        <fileNamePattern>${LOG_PATH}spring-boot.log.%d{yyyy-MM- 
dd}.%i.gz</fileNamePattern>
        <maxHistory>90</maxHistory>
        <maxFileSize>100KB</maxFileSize>
   </rollingPolicy>
</appender>

<logger name="org.springframework.web" level="info" additivity="false">
    <appender-ref ref="FILE" />
    <appender-ref ref="STDOUT" />
</logger>

<logger name="de.jarvia.baumangel" level="debug" additivity="false">
    <appender-ref ref="FILE" />
    <appender-ref ref="STDOUT" />
</logger>


<logger name="org.hibernate.SQL" level="error" additivity="false">
    <appender-ref ref="FILE" />
    <appender-ref ref="STDOUT" />
</logger>

<root level="info">
    <appender-ref ref="FILE" />
    <appender-ref ref="STDOUT" />
</root>


</configuration>


--- in application.properties

#### Logging files
logging.level.org.springframework.web=INFO
logging.file=log/spring-boot.log
logging.level.org.hibernate.SQL=ERROR
logging.level.de.jarvia.baumangel=DEBUG
#### Logging pattern for the console
logging.pattern.console=%d{dd.MM.yyyy HH:mm:ss} [%thread] %-5level 
%logger{36} - %msg%n

#### Logging pattern for file
logging.pattern.file=%d{dd.MM.yyyy HH:mm:ss} [%thread] %-5level 
%logger{36} - 
%msg%n


--- in pom.xml

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
<relativePath></relativePath>
</parent>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
4

0 回答 0