-
Notifications
You must be signed in to change notification settings - Fork 41.5k
Add Log4j2 rolling policy configuration #47260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hojooo
wants to merge
9
commits into
spring-projects:main
Choose a base branch
from
hojooo:log4j2-rolling-policy
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
+792
−5
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Signed-off-by: hojooo <ghwn5833@gmail.com>
- Add SpringBootTriggeringPolicy plugin supporting size, time, size-and-time, and cron strategies - Read rolling strategy parameters from LOG4J2_ROLLINGPOLICY_* system properties (fallback to attributes) - Register Boot plugin package in Log4J2LoggingSystem to ensure plugin discovery - Use SpringBootTriggeringPolicy under a top-level Policies wrapper in log4j2-file.xml Signed-off-by: hojooo <ghwn5833@gmail.com>
- Introduce rolling policy properties: strategy, time-based.interval, time-based.modulate, cron.schedule - Extend Log4j2RollingPolicySystemProperty with STRATEGY, TIME_INTERVAL, TIME_MODULATE, CRON_SCHEDULE - Propagate new properties in Log4j2LoggingSystemProperties (with deprecated fallback guarded for null) - Document new properties in configuration metadata - Update Log4j2LoggingSystemPropertiesTests to assert new system properties mappingAdd Log4j2 rolling policy configuration support Signed-off-by: hojooo <ghwn5833@gmail.com>
- Initialize with classpath:org/springframework/boot/logging/log4j2/log4j2-file.xml to validate file-based rolling - Unwrap CompositeTriggeringPolicy to locate nested SpringBootTriggeringPolicy and assert its delegate - Keep assertions for time, size-and-time, and cron strategies Signed-off-by: hojooo <ghwn5833@gmail.com>
Signed-off-by: hojooo <ghwn5833@gmail.com>
66fcaf7
to
b5d3b84
Compare
Signed-off-by: hojooo <ghwn5833@gmail.com>
….xml Signed-off-by: hojooo <ghwn5833@gmail.com>
Signed-off-by: hojooo <ghwn5833@gmail.com>
936ec72
to
05f8bb4
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
for: team-meeting
An issue we'd like to discuss as a team to make progress
status: waiting-for-triage
An issue we've not yet triaged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Hello! Log4j2 does not support rolling policies. So this PR adds basic rolling policy configuration property support for Log4j2. It introduces Log4j2 specific properties equivalent to the existing
logging.logback.rollingpolicy.*
properties, enabling consistent logging configuration through application.properties across different logging implementations.And advanced rolling strategy support to the Log4j2 rolling policy configuration. It introduces the
SpringBootTriggeringPolicy
plugin to enable various rolling strategies and strategy-specific detailed configuration through application.properties.Key Changes
1. Standardized Log4j2 Rolling Policy Properties (b98d74f)
We've added standard properties for Log4j2, similar to the existing
logging.logback.rollingpolicy.*
properties. Users can now easily control the rolling policy using the following attributes inapplication.properties
:2. Advanced Rolling Strategy (for commits after ddda65e)
A custom Log4j2 plugin,
SpringBootTriggeringPolicy
, has been introduced to support various advanced rolling strategies beyond simple size-based rolling.size
(default): Rolls files based on their size.time
: Rolls files based on a time interval.size-and-time
: Rolls when both size and time conditions are met.cron
: Rolls based on a cron expression schedule.Implementation Details
1. Property Standardization Implementation
Log4j2RollingPolicySystemProperty
Enum: An enum was implemented to map Spring Environment properties to system properties that Log4j2 can recognize (e.g.,max-file-size
->LOG4J2_ROLLINGPOLICY_MAX_FILE_SIZE
).Log4j2LoggingSystemProperties
Class: This class handles the automatic conversion of Spring'sDataSize
type to bytes and ensures backward compatibility with deprecated properties likelogging.file.max-size
.log4j2-file.xml
Modification: The configuration file was updated to reference the newly defined system properties using the${sys:PROPERTY_NAME}
syntax.2. Advanced Rolling Strategy Implementation
SpringBootTriggeringPolicy
Plugin: A customTriggeringPolicy
was implemented using Log4j2's@Plugin
annotation. Based on thestrategy
property, this plugin internally selects and delegates to the appropriate policy (e.g., SizeBasedTriggeringPolicy, TimeBasedTriggeringPolicy).log4j2-file.xml
Update: The<Policies>
block was modified to useSpringBootTriggeringPolicy
, with its parameters (maxFileSize, timeInterval, cronExpression, etc.) configured via system properties.Configuration Examples
Time-based Rolling
Size and Time Composite Rolling
Cron Expression-based Rolling
Compatibility
logging.file.max-size
andlogging.file.max-history
continue to work as expected.logging.log4j2.rollingpolicy.*
properties are set, they will take precedence over the older properties.