Skip to content

Make Selenium Easy

And Keep It That Way

  • Home
  • Share
  • Toggle search form

Log4j2 Tutorial 7 – Working Mechanism of Default Rollover Strategy

Posted on 02/19/2025 By admin

The RollingFileAppender is an OutputStreamAppender that writes to the File named in the fileName parameter and rolls the file over according to the TriggeringPolicy and the RolloverPolicy. A RollingFileAppender requires a TriggeringPolicy and a RolloverStrategy. The triggering policy determines when a rollover should be performed while the RolloverStrategy defines how the rollover should be done.

We are going to learn more about Default Rollover Strategy in this post.

Did you know that I have started a YouTube channel as well and I need your support to make it successful. Please do watch content then comment, like, share, and obviously subscribe.

There are multiple parameters are provided for RollingFileAppender but below are some which are used frequently and required to understand its working mechanism.

Parameter Name Type Description
fileName String The name of the file to write to. If the file, or any of its parent directories, do not exist, they will be created.
filePattern String The pattern of the file name of the archived log file. The format of the pattern is dependent on the RolloverPolicy that is used.

The default rollover strategy accepts both a date/time pattern and an integer from the filePattern attribute specified on the RollingFileAppender itself. If the date/time pattern is present it will be replaced with the current date and time values. If the pattern contains an integer it will be incremented on each rollover. If the pattern contains both a date/time and integer in the pattern the integer will be incremented until the result of the date/time pattern changes.

Parameter Name Type Description
fileIndex String If set to “max” (the default), files with a higher index will be newer than files with a smaller index. If set to “min”, file renaming and the counter will follow the Fixed Window strategy described below.
min integer The minimum value of the counter. The default value is 1.
max integer The maximum value of the counter. Once this values is reached older archives will be deleted on subsequent rollovers. The default value is 7.

The default rollover strategy supports three variations for incrementing the counter. To illustrate how it works, suppose that the min attribute is set to 1, the max attribute is set to 3, the file name is “foo.log”, and the file name pattern is “foo-%i.log”.

Number of rollovers Active output target Archived log files Description
0 foo.log – All logging is going to the initial file.
1 foo.log foo-1.log During the first rollover foo.log is renamed to foo-1.log. A new foo.log file is created and starts being written to.
2 foo.log foo-2.log, foo-1.log During the second rollover foo.log is renamed to foo-2.log. A new foo.log file is created and starts being written to.
3 foo.log foo-3.log, foo-2.log, foo-1.log During the third rollover foo.log is renamed to foo-3.log. A new foo.log file is created and starts being written to.
4 foo.log foo-3.log, foo-2.log, foo-1.log In the fourth and subsequent rollovers, foo-1.log is deleted, foo-2.log is renamed to foo-1.log, foo-3.log is renamed to foo-2.log and foo.log is renamed to foo-3.log. A new foo.log file is created and starts being written to.

By way of contrast, when the fileIndex attribute is set to “min” but all the other settings are the same the “fixed window” strategy will be performed.

Number of rollovers Active output target Archived log files Description
0 foo.log – All logging is going to the initial file.
1 foo.log foo-1.log During the first rollover foo.log is renamed to foo-1.log. A new foo.log file is created and starts being written to.
2 foo.log foo-1.log, foo-2.log During the second rollover foo-1.log is renamed to foo-2.log and foo.log is renamed to foo-1.log. A new foo.log file is created and starts being written to.
3 foo.log foo-1.log, foo-2.log, foo-3.log During the third rollover foo-2.log is renamed to foo-3.log, foo-1.log is renamed to foo-2.log and foo.log is renamed to foo-1.log. A new foo.log file is created and starts being written to.
4 foo.log foo-1.log, foo-2.log, foo-3.log In the fourth and subsequent rollovers, foo-3.log is deleted, foo-2.log is renamed to foo-3.log, foo-1.log is renamed to foo-2.log and foo.log is renamed to foo-1.log. A new foo.log file is created and starts being written to.

All the above points I have extracted from official Log4j2 documentation.

Log4j2 Example Codes

You can subscribe to my YouTube channel RetargetCommon to learn from video tutorials.

If you have any doubt, feel free to comment below.If you like my posts, please like, comment, share and subscribe.#ThanksForReading

#HappyLearning

Uncategorized

Post navigation

Previous Post: REST Assured Tutorial 61 – Deserialize Using JsonPath
Next Post: Resolutions 2020 for Testers

Related Posts

API Testing Tutorial Part 11 – Difference Between SOAP and Rest Web Services or API | Make Selenium Easy Uncategorized
image – Make Selenium Easy Uncategorized
SkipExceptionFailed – Make Selenium Easy Uncategorized
confirmPopup – Make Selenium Easy Uncategorized
java interview question Uncategorized
REST Assured Tutorial 48 – How To Pass Headers In Rest Assured Requests Uncategorized

Recent Posts

  • Getting Started with Selenium 4: What Is New and How to Upgrade from Selenium 3
  • Manual Testing
  • Baby Steps To Become Efficient Selenium-Java Automation Tester
  • Features of Selenium 4.0.0 Release – Java Binding
  • Part 1: Handling Drop-down Created Using SELECT Tag In Selenium

Recent Comments

No comments to show.

Archives

  • April 2026
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • April 2024
  • March 2024
  • February 2024
  • December 2023
  • October 2023
  • August 2023
  • November 2022
  • September 2022
  • August 2022
  • July 2022
  • May 2022
  • March 2022
  • October 2021
  • April 2021
  • March 2021
  • January 2021
  • December 2020
  • October 2020
  • September 2020
  • August 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • May 2019
  • December 2018
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • January 2018

Categories

  • Getting Started
  • Uncategorized

Copyright © 2026 Make Selenium Easy.

Powered by PressBook Masonry Dark