Skip to content

Add support for configuring Log4j2 rolling policy properties via application.properties, similar to Logback.#48876

Closed
timonin01 wants to merge 1 commit intospring-projects:mainfrom
timonin01:feature/log4j2-system-properties
Closed

Add support for configuring Log4j2 rolling policy properties via application.properties, similar to Logback.#48876
timonin01 wants to merge 1 commit intospring-projects:mainfrom
timonin01:feature/log4j2-system-properties

Conversation

@timonin01
Copy link

Summary

Add support for configuring Log4j2 rolling policy properties via application.properties, similar to Logback.

Changes

  • Add Log4J2RollingPolicySystemProperty enum for rolling policy system properties
  • Add Log4J2LoggingSystemProperties class to apply rolling policy properties
  • Update log4j2-file.xml to use system properties for rolling policy configuration
  • Add tests to verify rolling policy properties are correctly applied

Properties Added

The following properties are now supported:

  • logging.log4j2.rollingpolicy.file-name-pattern - Pattern for rolled-over log files
  • logging.log4j2.rollingpolicy.max-file-size - Maximum size of a single log file
  • logging.log4j2.rollingpolicy.total-size-cap - Total size cap for all log backups
  • logging.log4j2.rollingpolicy.max-history - Maximum number of log files to keep

Example Usage

logging.log4j2.rollingpolicy.max-file-size=20MB
logging.log4j2.rollingpolicy.max-history=10
logging.log4j2.rollingpolicy.total-size-cap=100MB

Related Issues

Closes #48323

This commit adds support for configuring Log4j2 rolling policy properties
(file-name-pattern, max-file-size, total-size-cap, max-history) through
application.properties, similar to how it's done for Logback.

- Add Log4J2RollingPolicySystemProperty enum defining rolling policy
  system properties
- Add Log4J2LoggingSystemProperties class extending LoggingSystemProperties
  to apply rolling policy properties from environment
- Update log4j2-file.xml to use system properties instead of hardcoded
  values for rolling policy configuration
- Add Log4J2LoggingSystemPropertiesTests to verify rolling policy properties are correctly applied

Closes spring-projectsgh-46468

Signed-off-by: Timonin Andrey <atimonin2006@gmail.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jan 17, 2026
@snicoll
Copy link
Member

snicoll commented Jan 17, 2026

Thanks but we already have a comprehensive PR that is being worked on for quite a while, see #47260

@snicoll snicoll closed this Jan 17, 2026
@snicoll snicoll added status: duplicate A duplicate of another issue and removed status: waiting-for-triage An issue we've not yet triaged labels Jan 17, 2026
@timonin01 timonin01 deleted the feature/log4j2-system-properties branch January 18, 2026 12:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: duplicate A duplicate of another issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants