gpt4 book ai didi

logging - 从 TimeBasedRollingPolicy 移动到 SizeAndTimeBasedRollingPolicy 以在每个 mignight 或最大大小翻转

转载 作者:行者123 更新时间:2023-12-04 01:49:17 26 4
gpt4 key购买 nike

当我使用以下附加程序时

<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



所以我改了 SizeAndTimeBasedFNATPSizeAndTimeBasedRollingPolicy
这给我留下了这个:
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<maxFileSize>10MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>

但后来我得到:

No TriggeringPolicy was set for the RollingFileAppender named APPLICATION



这让我认为没有这样的 TriggeringPolicy 所以我将 TriggeringPolicy 恢复为 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



我试图在每个午夜或最大尺寸之后实现翻转,以先到者为准。现在,我使用的是 logback 版本: 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com