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

Add test verifying log4j2 updateLoggers is called #5822

Merged
merged 1 commit into from
Jan 28, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.io.IOException;
import java.time.Duration;
import java.util.Iterator;
import java.util.concurrent.atomic.AtomicInteger;

import static java.util.Collections.emptyList;
import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -186,6 +187,27 @@ void asyncLogShouldNotBeDuplicated() throws IOException {
.until(() -> registry.get("log4j2.events").tags("level", "info").counter().count() == 3);
}

// see https://github.com/micrometer-metrics/micrometer/pull/872
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also add @Issue("#867")?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can, though I guess 867 is linked to from 872. Obviously out of scope for this PR, but since you reminded me, I wonder if we should get rid of that @Issue annotation entirely since we have no tooling that uses it and so it doesn't seem to add value over a comment without an annotation.

@Test
void shouldTriggerLoggersUpdateOnOpenAndClose() {
LoggerContext context = new LoggerContext("test");

AtomicInteger reconfigureCount = new AtomicInteger();
context.addPropertyChangeListener(event -> {
if (event.getNewValue() instanceof Configuration) {
reconfigureCount.incrementAndGet();
}
});

Log4j2Metrics metrics = new Log4j2Metrics(emptyList(), context);

assertThat(reconfigureCount.get()).isEqualTo(0);
metrics.bindTo(registry);
assertThat(reconfigureCount.get()).isEqualTo(1);
metrics.close();
assertThat(reconfigureCount.get()).isEqualTo(2);
}

@Test
void metricsFilterIsReused() {
LoggerContext loggerContext = new LoggerContext("test");
Expand Down
Loading