Spring boot - limited to 7 backup log files

In our spring-boot project, we use slf4j for logging purposes. Below are the settings that we added to the application.properties file

logging.file=/opt/logs/my_log.log logging.level.org.springframework.web=INFO logging.level.org.hibernate=INFO logging.level.nl.yestelecom.boss=DEBUG logging.level.com.github.isrsal.logging.LoggingFilter=DEBUG 

It generates only 7 backup files (my_log.log.1, my_log.log.2 ..., my_log.log.7) with each file 10.5MB in size, and after that logging does not occur at all.

Is there any way to change this behavior?

We looked at the available spring-boot properties, but found nothing. Any suggestion is appreciated.

+6
source share
3 answers

Spring-Boot only allows limited properties set in its application.properties. See here .

The default configuration (ready-made) used when using Spring-boot is defined in the base.xml file. See base.xml config here , which includes this appender file

There are 2 ways to add additional configuration.

  • Add login <spring.xml

If there is an XML log configuration code in the path to the project class with the name logback- spring.xml, it is selected during the initialization of Spring-Boot.

  1. Specify the configuration file from application.properties

Inside application.properties, use the following command to point to your own XML login

 logging.config= # Location of the logging configuration file. For instance `classpath:logback.xml` for Logback 

Once you add additional configuration using either of the above two steps, the rollover strategy can be mentioned in this custom XML, such as

 <?xml version="1.0" encoding="UTF-8"?> <configuration scan="true"> <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"> <encoder> <charset>UTF-8</charset> <Pattern>%d %-4relative [%thread] %-5level %logger{35} - %msg%n</Pattern> </encoder> </appender> <appender name="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.FixedWindowRollingPolicy"> <fileNamePattern>${LOG_FILE}.%i</fileNamePattern> <minIndex>1</minIndex> <maxIndex>10</maxIndex> </rollingPolicy> <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> <MaxFileSize>10MB</MaxFileSize> </triggeringPolicy> </appender> <root level="DEBUG"> <appender-ref ref="CONSOLE" /> <appender-ref ref="FILE"/> </root> </configuration> 
+11
source

SFL4J is just a shell. You need to add additional configuration for the log library:

 <configuration> <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>logFile.log</file> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <!-- daily rollover --> <fileNamePattern>logFile.%d{yyyy-MM-dd}.log</fileNamePattern> <!-- keep 30 days' worth of history capped at 3GB total size --> <maxHistory>30</maxHistory> <totalSizeCap>3GB</totalSizeCap> </rollingPolicy> <encoder> <pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n</pattern> </encoder> </appender> <root level="DEBUG"> <appender-ref ref="FILE" /> </root> </configuration> 

source

In this case, we have logs from the last 30 days, but no more than 3 GB.

+5
source

for spring-boot 2.0.0:

  • logging.file.max history
  • logging.file.max size

... and others See org.springframework.boot.logging.LoggingSystemProperties or https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/html/boot-features-logging.html#boot- features-logging-file-output

0
source

All Articles