Rav*_*iga 15 java spring logback slf4j spring-boot
在我们的spring-boot项目中,我们使用slf4j进行日志记录.以下是我们在application.properties文件中添加的配置
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
Run Code Online (Sandbox Code Playgroud)
它只生成7个备份文件(my_log.log.1,my_log.log.2 ...,my_log.log.7),每个文件的大小为10.5MB,之后根本不会发生日志记录.
有没有办法改变这种行为?
我们查看了spring-boot的可用属性,但没有找到任何东西.任何建议表示赞赏.
Dee*_*akV 22
Spring-Boot仅允许在其application.properties中配置有限属性.请参阅此处的列表.
Spring-boot使用的默认(开箱即用)配置在base.xml中定义.请参阅此处的base.xml配置,其中包含此File appender
有两种方法可以添加额外的配置
如果在项目的类路径中有一个名为logback-spring.xml的logback配置XML,则Spring-Boot会在初始化时获取它.
在application.properties中,使用以下内容指向自定义logback XML
logging.config= # Location of the logging configuration file. For instance `classpath:logback.xml` for Logback
Run Code Online (Sandbox Code Playgroud)
使用上述两个步骤中的任何一个添加额外配置后,可以在该自定义XML中提及翻转策略
<?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>
Run Code Online (Sandbox Code Playgroud)
SFL4J只是包装.您需要为logback库添加额外配置:
<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>
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我们有过去30天但不超过3GB的日志.
| 归档时间: |
|
| 查看次数: |
17949 次 |
| 最近记录: |