Skip to content

Rolling file policies

Rolling file policies determine the conditions under which a log file is rotated and how the old files are managed in logging frameworks like Log4j2^[600-developer__java__3-party__java-log4j2.md].

Configuration

Policies are typically defined within the <Policies> tag of a configuration file^[600-developer__java__3-party__java-log4j2.md]. They rely on specific triggers to initiate the rollover process.

Triggering Policies

  • Size-based: Rollover occurs when the active log file reaches a specified size.^[600-developer__java__3-party__java-log4j2.md]
  • Time-based: Rollover occurs based on a time schedule, often integrated into the file naming pattern (e.g., daily).^[600-developer__java__3-party__java-log4j2.md]

Rollover Strategy

The <DefaultRolloverStrategy> element is used to manage the lifecycle of the archived files^[600-developer__java__3-party__java-log4j2.md]. A common configuration is the max attribute, which defines the maximum number of archived files to retain^[600-developer__java__3-party__java-log4j2.md]. Once this limit is exceeded, older files are typically deleted during the next rollover event^[600-developer__java__3-party__java-log4j2.md].

File Patterns

When a rollover occurs, the current file is renamed based on the filePattern attribute^[600-developer__java__3-party__java-log4j2.md]. This pattern often includes date and time specifiers (e.g., %d{yyyy-MM-dd}) and an incrementing index (e.g., -%i) to differentiate multiple rollovers occurring within the same time period^[600-developer__java__3-party__java-log4j2.md].

  • Log4j2
  • [[Logging]]
  • [[Appenders]]

Sources

  • 600-developer__java__3-party__java-log4j2.md