From 684b65e80c8c1216d4890e350cadd72768a35f18 Mon Sep 17 00:00:00 2001 From: Ralph Goers Date: Thu, 13 Aug 2020 14:39:59 -0700 Subject: [PATCH 1/2] Remove ResourceUtils.getURL logging config check Remove `ResourceUtils.getURL` checking from `LoggingApplicationListener` so that logging systems can implement custom location support. Prior to this commit, we checked in the listener if the specified config location could be opened as a URL. This unfortunately prevents Log4J extensions such as `log4j-spring-cloud-config-client` from implementing configurable SSL and credentials support. See gh-22946 --- .../boot/context/logging/LoggingApplicationListener.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/logging/LoggingApplicationListener.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/logging/LoggingApplicationListener.java index de5e762c4b..05e16ef898 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/logging/LoggingApplicationListener.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/logging/LoggingApplicationListener.java @@ -53,7 +53,6 @@ import org.springframework.core.env.Environment; import org.springframework.core.log.LogMessage; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; -import org.springframework.util.ResourceUtils; import org.springframework.util.StringUtils; /** @@ -314,7 +313,6 @@ public class LoggingApplicationListener implements GenericApplicationListener { } else { try { - ResourceUtils.getURL(logConfig).openStream().close(); system.initialize(initializationContext, logConfig, logFile); } catch (Exception ex) { From 35994b061c379746f5a52f9edab54754446f32f0 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Fri, 28 Aug 2020 15:06:28 -0700 Subject: [PATCH 2/2] Polish 'Remove ResourceUtils.getURL logging config check' Extend `initializeSystem` to search the exception stack for a FileNotFoundException before reporting the error. This allows us to provide a similar stack trace to the one that used to be thrown when we had the `ResourceUtils.getURL` check. See gh-22946 --- .../context/logging/LoggingApplicationListener.java | 10 ++++++++-- .../logging/LoggingApplicationListenerTests.java | 7 ++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/logging/LoggingApplicationListener.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/logging/LoggingApplicationListener.java index 05e16ef898..99d2af7ab3 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/logging/LoggingApplicationListener.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/logging/LoggingApplicationListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 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. @@ -16,6 +16,7 @@ package org.springframework.boot.context.logging; +import java.io.FileNotFoundException; import java.util.Collections; import java.util.List; import java.util.Map; @@ -316,9 +317,14 @@ public class LoggingApplicationListener implements GenericApplicationListener { system.initialize(initializationContext, logConfig, logFile); } catch (Exception ex) { + Throwable exceptionToReport = ex; + while (exceptionToReport != null && !(exceptionToReport instanceof FileNotFoundException)) { + exceptionToReport = exceptionToReport.getCause(); + } + exceptionToReport = (exceptionToReport != null) ? exceptionToReport : ex; // NOTE: We can't use the logger here to report the problem System.err.println("Logging system failed to initialize using configuration from '" + logConfig + "'"); - ex.printStackTrace(System.err); + exceptionToReport.printStackTrace(System.err); throw new IllegalStateException(ex); } } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/logging/LoggingApplicationListenerTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/logging/LoggingApplicationListenerTests.java index 9701681107..9c46610d1d 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/logging/LoggingApplicationListenerTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/logging/LoggingApplicationListenerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 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. @@ -165,9 +165,10 @@ class LoggingApplicationListenerTests { addPropertiesToEnvironment(this.context, "logging.config=doesnotexist.xml"); assertThatIllegalStateException().isThrownBy(() -> { this.initializer.initialize(this.context.getEnvironment(), this.context.getClassLoader()); - assertThat(this.output) - .contains("Logging system failed to initialize using configuration from 'doesnotexist.xml'"); }); + assertThat(this.output) + .contains("Logging system failed to initialize using configuration from 'doesnotexist.xml'") + .doesNotContain("JoranException"); } @Test