Log4j2之RollingFileAppender学习笔记

RollingFileAppender

The RollingFileAppender is an OutputStreamAppender that writes to the File named in the fileName parameter and rolls the file over according the TriggeringPolicy and the TolloverPolicy. The RollingFileAppender uses a RollingFileManager to actually perform the file I/O and perform the rollover.
A RollingFileAppender requires a TriggeringPolicy and a RolloverStrategy. The triggering policy determines if a rollover should be performed while the RolloverStrategy defines how the rollover should be done.

Triggering Policies

Composite Triggering Policy

The CompositeTriggeringPolicy combines multiple triggering policies and returns true if any of the configured policies return true. The CompositeTriggeringPolicy is configured simply by wrapping other policies in a Policies element.
Cron Triggering Policy
The CronTriggeringPolicy triggers rollover based on a cron expression.

CronTriggeringPolicy Parameters

Parameter NameTypeDescription
scheduleStringThe cron expression. The expression is the same as what is allowed in the Quartz scheduler. See CronExpression for a full description of the expression.
evaluateOnStartupbooleanOn startup the cron expression will be evaluated against the file’s last modification timestamp. If the cron expression indicates a rollover should have occurred between that time and the current time the file will be immediately rolled over.

OnStartup Triggering Policy

The OnStartupTriggeringPolicy policy causes a rollover if the log file is older than the current JVM’s start time and the minimum file size if met or exceeded.

OnStartupTriggeringPolicy Parameters

Parameter NameTypeDescription
minSizelongThe minimum size the file must have to rollover. A size of zero will cause a roll over no matter what the file size is. The default value is 1, which will prevent rolling over an empty file.

SizeBased Triggering Policy
The SizeBasedTriggeringPolicy causes a rollover once the file has reached the specified size. The size can be specified in bytes, with the suffix KB, MB, or GB for example 20MB.

TimeBased Triggering Policy
The TimeBasedTriggeringPolicy causes a rollover once the date/time pattern no longer applies to the active file. This policy accepts an interval attribute which indicates how frequently the rollover should occur based on the time pattern and a modulate boolean attribute.

TimeBasedTriggeringPolicy Parameters

Parameter NameTypeDescription
intervalintegerHow often a rollover should occur based on the most specific time unit in the date pattern. For example, with a date pattern with hours as the most specific item and increment of 4 rollovers would occur every 4 hours. The default value is 1.
modulatebooleanIndicates whether the interval should be adjusted to cause the next rollover to occur on the interval boundary. For example, if the item is hours, the current hour is 3 am and the interval is 4 then the first rollover will occur at 4 am and then next ones will occur at 8am, noon, 4pm, etc.
maxRandomDelayintegerIndicates the maximum number of seconds to randomly delay a rollover. By default, this is 0 which indicates no delay. This setting is useful on serers where multiple applications are configured to rollover log files at the same time and can spread the load of doing so across time.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值