Skip to content

Commit cfcdac9

Browse files
committed
Extract LOGGER_CONTEXT_CLASS_NAME constant and unify log messages
- Moved the repeated string "org.apache.logging.log4j.core.LoggerContext" to a private static final constant - Used the constant in Class.forName() and ConditionOutcome messages - Unified inconsistent messages: changed "Logger context" to "LoggerContext" for consistency with the class name Signed-off-by: wonyongg <[email protected]>
1 parent 740b00e commit cfcdac9

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/Log4J2MetricsAutoConfiguration.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,22 @@ public Log4j2Metrics log4j2Metrics() {
5454

5555
static class Log4JCoreLoggerContextCondition extends SpringBootCondition {
5656

57+
private static final String LOGGER_CONTEXT_CLASS_NAME = "org.apache.logging.log4j.core.LoggerContext";
58+
5759
@Override
5860
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
5961
LoggerContext loggerContext = LogManager.getContext(false);
6062
try {
61-
if (Class.forName("org.apache.logging.log4j.core.LoggerContext").isInstance(loggerContext)) {
63+
if (Class.forName(LOGGER_CONTEXT_CLASS_NAME).isInstance(loggerContext)) {
6264
return ConditionOutcome
63-
.match("LoggerContext was an instance of org.apache.logging.log4j.core.LoggerContext");
65+
.match("LoggerContext was an instance of " + LOGGER_CONTEXT_CLASS_NAME);
6466
}
6567
}
6668
catch (Throwable ex) {
6769
// Continue with no match
6870
}
6971
return ConditionOutcome
70-
.noMatch("Logger context was not an instance of org.apache.logging.log4j.core.LoggerContext");
72+
.noMatch("LoggerContext was not an instance of " + LOGGER_CONTEXT_CLASS_NAME);
7173
}
7274

7375
}

0 commit comments

Comments
 (0)