-
Notifications
You must be signed in to change notification settings - Fork 1k
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 Log4j2Metrics
when LoggerContext#reconfigure
is called
#5756
Comments
I'm not familiar with how the details of how reconfiguring works. Could you share a snippet of code demonstrating what is being done? Ideally if it can be put in a unit test that is minimal (i.e. doesn't involve Spring), we can add it to our tests when we address this and ensure it works now and going forward. I wonder if there is a way we can register a callback that is run when reconfiguration happens. |
I just change some config (any) at Nacos, and that will trigger a RefreshEvent of Spring. Then, the logging system of Spring will load loadConfiguration again.
` |
I can try to make some tests about this |
Adding a listener of PropertyChangeEvent may be a solution |
I add some code as below,and it works for my project. The problem is involved by Spring's Refresh Event, I cannot give some unit tests.
|
Hi, We have a similar issue with the log4j2 metrics. In our log4j2 configuration file, we use Here is a failing testcase that I believe recreates the issue. @Test
void doesNotRebindWhenConfigurationIsReloaded() {
MeterRegistry registry = new SimpleMeterRegistry();
LoggerContext context = (LoggerContext) LogManager.getContext(false);
try (Log4j2Metrics metrics = new Log4j2Metrics(emptyList(), context)) {
metrics.bindTo(registry);
Logger logger = context.getLogger(getClass());
Configurator.setLevel(logger, Level.INFO);
logger.info("first");
// This will reload the configuration, metrics will not be rebound and the counter will not be incremented
context.reconfigure();
logger.info("second");
// This equals to 1 because the metrics are not rebound
assertThat(registry.get("log4j2.events").tags("level", "info").counter().count()).isEqualTo(2);
}
} I think there might be something that can be done using log4j2 configuration listeners. |
Log4j2Metrics
when LoggerContext#reconfigure
is called
@pativa thank you for the unit test to reproduce this. If you have an idea for a good solution, feel free to send a pull request. We would be happy to review. I have marked this issue as |
Sure, I checked it out and think I have a working fix. I'll create a PR! |
Describe the bug
Now,log4j2Metrics is registed when server starting up. But when Log4j2 LoggerContexted is reconfigured because of config being changed, the filter will not work.
Environment
To Reproduce
How to reproduce the bug:
After a spring server starts up, we change some log4j2's config, logging level for example and Log4j2's reconfigure will be triggered. After this, the filter in log4j2Metrics will not work.
Expected behavior
log4j2Metrics always work
The text was updated successfully, but these errors were encountered: