Skip to content

Commit ddb9979

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 ddb9979

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,20 @@ 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)) {
62-
return ConditionOutcome
63-
.match("LoggerContext was an instance of org.apache.logging.log4j.core.LoggerContext");
63+
if (Class.forName(LOGGER_CONTEXT_CLASS_NAME).isInstance(loggerContext)) {
64+
return ConditionOutcome.match("LoggerContext was an instance of " + LOGGER_CONTEXT_CLASS_NAME);
6465
}
6566
}
6667
catch (Throwable ex) {
6768
// Continue with no match
6869
}
69-
return ConditionOutcome
70-
.noMatch("Logger context was not an instance of org.apache.logging.log4j.core.LoggerContext");
70+
return ConditionOutcome.noMatch("LoggerContext was not an instance of " + LOGGER_CONTEXT_CLASS_NAME);
7171
}
7272

7373
}

0 commit comments

Comments
 (0)