Skip to content

Commit

Permalink
Add log4j2 async test (micrometer-metrics#2176)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennys Fredericci authored and shakuzen committed Jul 23, 2020
1 parent 209d1f3 commit eb5515e
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
3 changes: 3 additions & 0 deletions micrometer-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ dependencies {

testCompile 'ru.lanwen.wiremock:wiremock-junit5:1.2.0'
testCompile 'com.github.tomakehurst:wiremock:latest.release'

// Log4j2 Async dependency
testImplementation 'com.lmax:disruptor:3.4.2'
}

shadowJar {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,20 @@ void noDuplicateLoggingCountWhenMultipleNonAdditiveLoggersShareConfig() {
logger1.info("Hello, world!");
assertThat(registry.get("log4j2.events").tags("level", "info").counter().count()).isEqualTo(1);
}

@Issue("#2176")
@Test
void asyncLogShouldNotBeDuplicated() throws IOException {
ConfigurationSource source = new ConfigurationSource(getClass().getResourceAsStream("/binder/logging/log4j2-async-logger.xml"));
Configurator.initialize(null, source);

Logger logger = LogManager.getLogger(Log4j2MetricsTest.class);

new Log4j2Metrics().bindTo(registry);

assertThat(registry.get("log4j2.events").tags("level", "info").counter().count()).isEqualTo(0);
logger.info("Hello, world!");
assertThat(registry.get("log4j2.events").tags("level", "info").counter().count()).isEqualTo(1);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2019 VMware, Inc.
<p>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
<p>
https://www.apache.org/licenses/LICENSE-2.0
<p>
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<Configuration status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
</Appenders>
<Loggers>
<AsyncRoot level="info" additivity="false">
<AppenderRef ref="Console"/>
</AsyncRoot>
</Loggers>
</Configuration>

0 comments on commit eb5515e

Please sign in to comment.