diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/Log4J2MetricsAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/Log4J2MetricsAutoConfiguration.java index 9da1b3aef57..bfed81461ac 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/Log4J2MetricsAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/Log4J2MetricsAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -54,20 +54,20 @@ public class Log4J2MetricsAutoConfiguration { static class Log4JCoreLoggerContextCondition extends SpringBootCondition { + private static final String LOGGER_CONTEXT_CLASS_NAME = "org.apache.logging.log4j.core.LoggerContext"; + @Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { LoggerContext loggerContext = LogManager.getContext(false); try { - if (Class.forName("org.apache.logging.log4j.core.LoggerContext").isInstance(loggerContext)) { - return ConditionOutcome - .match("LoggerContext was an instance of org.apache.logging.log4j.core.LoggerContext"); + if (Class.forName(LOGGER_CONTEXT_CLASS_NAME).isInstance(loggerContext)) { + return ConditionOutcome.match("LoggerContext was an instance of " + LOGGER_CONTEXT_CLASS_NAME); } } catch (Throwable ex) { // Continue with no match } - return ConditionOutcome - .noMatch("Logger context was not an instance of org.apache.logging.log4j.core.LoggerContext"); + return ConditionOutcome.noMatch("LoggerContext was not an instance of " + LOGGER_CONTEXT_CLASS_NAME); } }