Merge branch '2.7.x'

Closes gh-31409
This commit is contained in:
Phillip Webb 2022-06-16 15:36:29 -07:00
commit 657fa3e64e
5 changed files with 16 additions and 10 deletions

View File

@ -23,6 +23,7 @@ import org.junit.jupiter.api.Test;
import org.springframework.boot.actuate.autoconfigure.metrics.test.MetricsRun;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.boot.testsupport.classpath.ClassPathExclusions;
import org.springframework.boot.testsupport.classpath.ClassPathOverrides;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -34,6 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Andy Wilkinson
*/
@ClassPathExclusions("log4j-to-slf4j-*.jar")
@ClassPathOverrides("org.apache.logging.log4j:log4j-core:2.11.1")
class Log4J2MetricsWithLog4jLoggerContextAutoConfigurationTests {

View File

@ -21,6 +21,7 @@ import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.boot.testsupport.classpath.ClassPathExclusions;
import org.springframework.boot.testsupport.classpath.ClassPathOverrides;
import static org.assertj.core.api.Assertions.assertThat;
@ -31,6 +32,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Andy Wilkinson
*/
@ClassPathExclusions("log4j-to-slf4j-*.jar")
@ClassPathOverrides({ "org.apache.logging.log4j:log4j-core:2.9.0", "org.apache.logging.log4j:log4j-slf4j-impl:2.9.0" })
class MetricsAutoConfigurationWithLog4j2AndLogbackTests {

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2022 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.
@ -242,11 +242,8 @@ final class ModifiedClassPathClassLoader extends URLClassLoader {
private final AntPathMatcher matcher = new AntPathMatcher();
private ClassPathEntryFilter(MergedAnnotation<ClassPathExclusions> annotation) {
this.exclusions = new ArrayList<>();
this.exclusions.add("log4j-*.jar");
if (annotation.isPresent()) {
this.exclusions.addAll(Arrays.asList(annotation.getStringArray(MergedAnnotation.VALUE)));
}
this.exclusions = annotation.getValue(MergedAnnotation.VALUE, String[].class).map(Arrays::asList)
.orElse(Collections.emptyList());
}
private boolean isExcluded(URL url) {

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2022 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.
@ -28,8 +28,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Andy Wilkinson
*/
// Log4j2 is implicitly excluded due to LOG4J-2030
@ClassPathExclusions("logback-*.jar")
@ClassPathExclusions({ "log4j-*.jar", "logback-*.jar" })
class LogbackAndLog4J2ExcludedLoggingSystemTests {
@Test

View File

@ -52,6 +52,8 @@ import org.springframework.boot.logging.LoggerConfiguration;
import org.springframework.boot.logging.LoggingInitializationContext;
import org.springframework.boot.logging.LoggingSystem;
import org.springframework.boot.logging.LoggingSystemProperties;
import org.springframework.boot.testsupport.classpath.ClassPathExclusions;
import org.springframework.boot.testsupport.classpath.ClassPathOverrides;
import org.springframework.boot.testsupport.system.CapturedOutput;
import org.springframework.boot.testsupport.system.OutputCaptureExtension;
import org.springframework.mock.env.MockEnvironment;
@ -76,6 +78,8 @@ import static org.mockito.Mockito.times;
* @author Madhura Bhave
*/
@ExtendWith(OutputCaptureExtension.class)
@ClassPathExclusions("logback-*.jar")
@ClassPathOverrides("org.apache.logging.log4j:log4j-slf4j-impl:2.17.2")
class Log4J2LoggingSystemTests extends AbstractLoggingSystemTests {
private final TestLog4J2LoggingSystem loggingSystem = new TestLog4J2LoggingSystem();
@ -250,9 +254,11 @@ class Log4J2LoggingSystemTests extends AbstractLoggingSystemTests {
@Test
void loggingThatUsesJulIsCaptured(CapturedOutput output) {
String name = getClass().getName();
this.loggingSystem.beforeInitialize();
this.loggingSystem.initialize(this.initializationContext, null, null);
java.util.logging.Logger julLogger = java.util.logging.Logger.getLogger(getClass().getName());
this.loggingSystem.setLogLevel(name, LogLevel.TRACE);
java.util.logging.Logger julLogger = java.util.logging.Logger.getLogger(name);
julLogger.setLevel(java.util.logging.Level.INFO);
julLogger.severe("Hello world");
assertThat(output).contains("Hello world");