罗氏file max over_fileappender rollover_appender name(4)

电脑杂谈  发布时间:2017-02-13 04:00:19  来源:网络整理

这个策略基于时间,比如说基于 day 或者 month 的滚动,同时实现了 RollingPolicy 接口和 TriggeringPolicy 接口,既定义了如何滚动,也定义了何时滚动。

TimeBasedRollingPolicy 只有一个必须的属性 fileNamePattern 和几个可选的属性。

fileNamePattern 包含实际的文件名,以及一个 %d 标识,这个标识的用法是 %d{},其中大括号里面是遵循 java.text.SimpleDataFormat 格式的日期模式,logback 会根据这个日期模式的最小单位来推断出是根据天、月、年还是分钟、小时来进行滚动的。

RollingFileAppender 有一个 file 属性,在配合 TimeBasedRollingPolicy 使用的时候,这个 file 的属性是否被设置,有着不同的区别。如果 file 属性设置了,那么每次新记录的日志将会记录到这个文件,当滚动时需要重命名的时候,则将这个文件名以 fileNamePattern 指定的模式进行重命名和归档。如果 file 属性没有进行设置,那么每次新纪录的日志会记录到根据 fileNamePattern 指定的当前日志文件里。

如果有多个 %d 标识,那么必须有一个是 primary 的,其它的为 auxiliary 的。例如 /var/log/%d{yyyy/MM, aux}/myapplication.%d{yyyy-MM-dd}.log 。同时,fileNamePattern 支持填写 Time Zone,例如 aFolder/test.%d{yyyy-MM-dd-HH, UTC}.log。

maxHistory 属性指定要保留多长时间的日志,依据从 fileNamePattern 中推断出来的单位。

totalSizeGap 属性限制了日志文件的大小总共不能超过的大小。

cleanHistoryOnStart 指定了是否重启应用的时候删除之前的归档日志。

以下是一些常见的 fileNamePattern,以及它们的作用。

fileNamePatternRollover scheduleExample

Daily rollover (at midnight). Due to the omission of the optional time and date pattern for the %d token specifier, the default pattern of yyyy-MM-dd is assumed, which corresponds to daily rollover.

If the file property not set: During November 23rd, 2006, logging output will go to the file /wombat/foo.2006-11-23. At midnight and for the rest of the 24th, logging output will be directed to /wombat/foo.2006-11-24. If the file property set to /wombat/foo.txt: During November 23rd, 2006, logging output will go to the file /wombat/foo.txt. At midnight, foo.txt will be renamed as /wombat/foo.2006-11-23. A new /wombat/foo.txt file will be created and for the rest of November 24th logging output will be directed to foo.txt.


本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/jisuanjixue/article-32110-4.html

相关阅读
    发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

    热点图片
    拼命载入中...