Merge pull request #22946 from rgoers
* pr/22946: Polish 'Remove ResourceUtils.getURL logging config check' Remove ResourceUtils.getURL logging config check Closes gh-22946
This commit is contained in:
commit
38db582af1
|
|
@ -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;
|
||||
|
|
@ -53,7 +54,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,13 +314,17 @@ public class LoggingApplicationListener implements GenericApplicationListener {
|
|||
}
|
||||
else {
|
||||
try {
|
||||
ResourceUtils.getURL(logConfig).openStream().close();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue