作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当我使用以下附加程序时
<appender name="APPLICATION"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>D:/logs/log.txt</file>
<append>true</append>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>%p %d [%t] %L - %m%n</Pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- rollover daily -->
<fileNamePattern>D:/logs/log.%d{yyyy-MM-dd}.%i.txt</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>10MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<!-- keep 30 days' worth of history -->
<maxHistory>30</maxHistory>
</rollingPolicy>
</appender>
SizeAndTimeBasedFNATP is deprecated. Use SizeAndTimeBasedRollingPolicy instead
SizeAndTimeBasedFNATP
至
SizeAndTimeBasedRollingPolicy
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<maxFileSize>10MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
No TriggeringPolicy was set for the RollingFileAppender named APPLICATION
SizeAndTimeBasedFNATP
并将滚动策略从
TimeBasedRollingPolicy
更改为至
SizeAndTimeBasedRollingPolicy
.
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<!-- rollover daily -->
<fileNamePattern>D:/logs/log.%d{yyyy-MM-dd}.%i.txt</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>10MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<!-- keep 30 days' worth of history -->
<maxHistory>30</maxHistory>
</rollingPolicy>
TriggeringPolicy has not started. RollingFileAppender will not start
1.2.3
最佳答案
终于想通了maxFileSize
必须在 timeBasedFileNamingAndTriggeringPolicy
之外和 SizeAndTimeBasedRollingPolicy
不需要这个。因此,根据时间和大小(以先到者为准)滚动的最终 logback.xml 变为:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!-- Send debug messages to System.out -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%p %d [%t] %L - %m%n</pattern>
</encoder>
</appender>
<appender name="APPLICATION" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>D:/logs/log.txt</file>
<append>true</append>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>%p %d [%t] %L - %m%n</Pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<!-- rollover daily -->
<fileNamePattern>D:/logs/log.%d{yyyy-MM-dd HH}.%i.txt</fileNamePattern>
<maxFileSize>5GB</maxFileSize>
<!-- keep 30 days' worth of history -->
<maxHistory>30</maxHistory>
<totalSizeCap>20GB</totalSizeCap>
</rollingPolicy>
</appender>
<logger name="javaportreader" level="INFO" additivity="false">
<appender-ref ref="STDOUT" />
</logger>
<logger name="application" level="DEBUG" additivity="false">
<appender-ref ref="APPLICATION"/>
</logger>
<!-- By default, the level of the root level is set to DEBUG -->
<root level="DEBUG">
<appender-ref ref="STDOUT" />
</root>
<root level="INFO">
<appender-ref ref="APPLICATION"/>
</root>
</configuration>
关于logging - 从 TimeBasedRollingPolicy 移动到 SizeAndTimeBasedRollingPolicy 以在每个 mignight 或最大大小翻转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54033579/
当我使用以下附加程序时 D:/logs/log.txt true %p %d [%t] %L - %m%n
我是一名优秀的程序员,十分优秀!