Skip to content

Logging config URLs with query parameters are not detected as XML #37039

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
* @author Dave Syer
* @author Andy Wilkinson
* @author Ben Hale
* @author Yanming Zhou
* @since 1.0.0
*/
public class LogbackLoggingSystem extends AbstractLoggingSystem implements BeanFactoryInitializationAotProcessor {
Expand Down Expand Up @@ -275,7 +276,7 @@ private void reportConfigurationErrorsIfNecessary(LoggerContext loggerContext) {

private void configureByResourceUrl(LoggingInitializationContext initializationContext, LoggerContext loggerContext,
URL url) throws JoranException {
if (url.toString().endsWith(".xml")) {
if (url.getPath().endsWith(".xml")) {
JoranConfigurator configurator = new SpringBootJoranConfigurator(initializationContext);
configurator.setContext(loggerContext);
configurator.doConfigure(url);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
* @author Eddú Meléndez
* @author Scott Frederick
* @author Jonatan Ivanov
* @author Yanming Zhou
*/
@ExtendWith(OutputCaptureExtension.class)
class LogbackLoggingSystemTests extends AbstractLoggingSystemTests {
Expand Down Expand Up @@ -782,6 +783,25 @@ void whenConfigurationErrorIsDetectedUnderlyingCausesAreIncludedAsSuppressedExce
.hasAtLeastOneElementOfType(DynamicClassLoadingException.class));
}

@Test
void whenConfigLocationIsNotXmlThenIllegalArgumentExceptionShouldBeThrown() {
this.loggingSystem.beforeInitialize();
assertThatIllegalStateException()
.isThrownBy(() -> initialize(this.initializationContext, "file:///logback-nonexistent.txt",
getLogFile(tmpDir() + "/tmp.log", null)))
.satisfies((ex) -> assertThat(ex.getCause()).isInstanceOf(IllegalArgumentException.class)
.hasMessageStartingWith("Unsupported file extension"));
}

@Test
void whenConfigLocationIsXmlAndHasQueryParametersThenIllegalArgumentExceptionShouldNotBeThrown() {
this.loggingSystem.beforeInitialize();
assertThatIllegalStateException()
.isThrownBy(() -> initialize(this.initializationContext, "file:///logback-nonexistent.xml?raw=true",
getLogFile(tmpDir() + "/tmp.log", null)))
.satisfies((ex) -> assertThat(ex.getCause()).isNotInstanceOf(IllegalArgumentException.class));
}

private void initialize(LoggingInitializationContext context, String configLocation, LogFile logFile) {
this.loggingSystem.getSystemProperties((ConfigurableEnvironment) context.getEnvironment()).apply(logFile);
this.loggingSystem.beforeInitialize();
Expand Down