Merge branch '3.4.x'

Closes gh-45990
This commit is contained in:
Stéphane Nicoll 2025-06-17 14:26:18 +02:00
commit 28c095c3be
1 changed files with 6 additions and 6 deletions

View File

@ -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);
}
}