在配置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>