除非有新日志,否则TimeBasedRollingPolicy不会滚动 [英] TimeBasedRollingPolicy not rolling unless there are new logs

查看:2135
本文介绍了除非有新日志,否则TimeBasedRollingPolicy不会滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的配置:

<appender name="myAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <append>true</append>
    <file>mylogs.log</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
        <!-- daily rollover -->
        <fileNamePattern>mylogs-%d{yyyy-MM-dd_HH-mm}.log</fileNamePattern>

        <!-- keep 30 days' worth of history -->
        <maxHistory>30</maxHistory>
    </rollingPolicy>

    <encoder>
        <pattern>%d{HH:mm:ss.SSS} %-5level %logger{36} [%thread] - %M:%L - %msg%n</pattern>
    </encoder>
    <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
        <level>INFO</level>
    </filter>
</appender>

根据此处找到的logback文档( http://logback.qos.ch/manual/appenders.html#TimeBasedRollingPolicy ),文件将根据我的%每分钟翻转d {yyyy-MM-dd_HH-mm} fileNamePattern。

According to the logback's document found here (http://logback.qos.ch/manual/appenders.html#TimeBasedRollingPolicy) , file will be rollover every minute based on my %d{yyyy-MM-dd_HH-mm} fileNamePattern.

我观察了它是如何工作的,这是我的发现:

I observed how this works and here are my findings:


  • 它没有不会很快创建一个日志文件。

  • 它只会在新日志到达时创建前一分钟的日志文件。 (例如,我在晚上11:53有一个日志,现在是晚上11:55,它在下午11点54分点击它时不会立即创建一个新的日志文件,但是当一个新的日志出现时,请说明晚上11:56,它现在创建了晚上11:53的文件。)

我错过了什么,我以为它会创建一个日志每分钟发送一次文件?

Am I missing something, I thought it will create a log file every minute?

推荐答案

在您链接的文档部分进一步向下滚动,您会发现:

Scroll down further in the section of the documentation you linked and you will find this:


由于各种技术原因,翻转不是时钟驱动的,而是取决于记录事件的到来。例如,在2002年3月8日,假设fileNamePattern设置为yyyy-MM-dd(每日翻转),则午夜之后第一个事件的到达将触发翻转。如果在午夜之后的23分47秒没有记录事件,那么翻转实际上将发生在3月9日00:23'47 AM而不是0:00 AM。因此,根据事件的到达率,可能会以一些延迟触发翻转。但是,无论延迟如何,翻转算法都是正确的,因为在某个时间段内生成的所有日志记录事件都将在正确的文件中输出,并限定该时间段。

For various technical reasons, rollovers are not clock-driven but depend on the arrival of logging events. For example, on 8th of March 2002, assuming the fileNamePattern is set to yyyy-MM-dd (daily rollover), the arrival of the first event after midnight will trigger a rollover. If there are no logging events during, say 23 minutes and 47 seconds after midnight, then rollover will actually occur at 00:23'47 AM on March 9th and not at 0:00 AM. Thus, depending on the arrival rate of events, rollovers might be triggered with some latency. However, regardless of the delay, the rollover algorithm is known to be correct, in the sense that all logging events generated during a certain period will be output in the correct file delimiting that period.

短版本:它不是时间触发的,而是由日志事件触发的。没有记录事件意味着没有翻转。在设置为每分钟翻转的配置中,这意味着没有任何记录事件到达的任何分钟的文件。

Short version: It's not time-triggered, but logging-event-triggered. No logging events means no rollover. In a configuration set to rollover each minute that means there will be no files for any minute for which no logging-events arrive.

这篇关于除非有新日志,否则TimeBasedRollingPolicy不会滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆