Logback rollingFileAppender xml不会滚动或删除旧的归档日志 [英] Logback rollingFileAppender xml not rolling over or deleting old archived logs

查看:329
本文介绍了Logback rollingFileAppender xml不会滚动或删除旧的归档日志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是注销的一部分:

<appender name="APP_LOG"
              class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${APP_HOME}/loader.log</file>
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <Pattern>
                %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
            </Pattern>
        </encoder>

        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <!-- rollover daily -->
            <fileNamePattern>${APP_HOME}/archived/loader.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
            <timeBasedFileNamingAndTriggeringPolicy
                    class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <maxFileSize>10MB</maxFileSize>
            </timeBasedFileNamingAndTriggeringPolicy>
            <!-- Keep logs max for x days -->
            <maxHistory>1</maxHistory>
            <cleanHistoryOnStart>true</cleanHistoryOnStart>
        </rollingPolicy>

    </appender>

这应该每天创建一个新的日志文件.今天是2016年1月13日,因此,如果2016年1月12日没有日志,应将当前日志放入loader.2016-01-12.0.log,然后创建一个新的日志文件,对吗?不是那样的.

This should create a new log file every day. Today is Jan-13-2016, therefore if there is no log for Jan-12-2016 it should just put the current log into loader.2016-01-12.0.log and then create a new log file right? It's not doing that.

它也应该删除文件loader.2015-12-30.0.log和loader.2016-01-11.0.log,但也没有这样做.

It should also be deleting the files loader.2015-12-30.0.log and loader.2016-01-11.0.log but it's not doing that either.

我所要做的就是在基于Eclipse的IDE中启动应用程序,并且我可以验证每次应用程序运行时日志文件loader.log都在变化.这意味着登录已开始,但是由于某种原因,它无法正确清除旧文件.请帮忙吗?

All I'm doing is starting the application in an Eclipse based IDE, and I can verify that the log file loader.log is changing every time the application runs. Which means logback is starting, but for some reason it's not cleaning up old files properly. Please help?

推荐答案

TimeBasedRollingPolicy 指定maxHistory的单位为月,而不是天(如果您的滚动方式是每月).

The Logback documentation for TimeBasedRollingPolicy specifies that the unit of maxHistory is months, not days (if your rolling pattern is a monthly one).

关于几天之内没有创建日志的空日志文件(大小为0)的创建,我记得log4j并未创建它们. log4j中的OOTB日志轮换是 passive ,并且仅在新的一天将日志语句发送到log4j时才触发.

With regards to the creation of an empty log file (size 0) for days where no logs were created, I recall that log4j didn't create them. OOTB log rotation in log4j was passive and the triggered only when a log statement was sent to log4j in a new day.

我认为Logback的行为类似,但是我正在检查,我将尽快更新此答案.

I would assume that Logback behaves similarly, but I'm checking and I will update this answer soon.

修改:已确认. TimeBasedRollingPolicy不会在上一条日志语句和当前日志语句之间的任何完全经过的中间天中创建大小为零的文件.

Confirmed. The TimeBasedRollingPolicy does not create zero-sized files for any fully elapsed intermediate days between the last log statement and the current log statement.

也就是说,如果您的上一条每日轮换的日志语句位于 2015-01-01 上,而下一条语句位于 2015-01-13 ,则后者语句已处理,此时Logback仍将打开 2015-01-01 的文件.它会注意到并触发翻转,该翻转基本上包括:

That is, if your last log statement with daily rotation was on 2015-01-01 and your next statement is on 2015-01-13, when the latter statement is processed, at that point Logback still would have the file for 2015-01-01 open. It would notice and it would trigger a rollover, which basically consists of:

  1. renaming the current file with the archival pattern – and –
  2. opening a new file.

但是它不会创建任何中间零字节文件.

But it won't create any intermediate zero-byte files.

这篇关于Logback rollingFileAppender xml不会滚动或删除旧的归档日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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