Skip to content
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

Rebind log4j2 metrics if configuration is changed #5810

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

pativa
Copy link

@pativa pativa commented Jan 17, 2025

Describe the issue

This PR is intended to fix #5756

When log4j2 metrics are reconfigured, metrics will no longer be recorded. For example, if monitorInterval (docs) is configured to 30 is used and configuration is reloaded after application start, metrics would only be recorded for the first 30 seconds.


By using a PropertyChangeListener, it looks like we can register the MetricsFilter in much the same way, but it will be rebound after reloading the configuration. All the previous tests seem to pass too when using this method of configuration.

* Use `PropertyChangeListener` to add the `MetricsFilter` to log4j2 if configuration is reloaded
* When adding filters, check if the filter is already added
* Keep `metricFilters` in a `HashMap` to avoid creating new filters each time configuration is reloaded

Signed-off-by: Patrik Ivarsson <[email protected]>
Signed-off-by: Patrik Ivarsson <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rebind Log4j2Metrics when LoggerContext#reconfigure is called
1 participant