Improve handling of Throwable from logging system init
Closes gh-38885
This commit is contained in:
parent
6755a937a2
commit
c10f78ec5a
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2023 the original author or authors.
|
* Copyright 2012-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -335,7 +335,7 @@ public class LoggingApplicationListener implements GenericApplicationListener {
|
||||||
system.initialize(initializationContext, logConfig, logFile);
|
system.initialize(initializationContext, logConfig, logFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Throwable ex) {
|
||||||
Throwable exceptionToReport = ex;
|
Throwable exceptionToReport = ex;
|
||||||
while (exceptionToReport != null && !(exceptionToReport instanceof FileNotFoundException)) {
|
while (exceptionToReport != null && !(exceptionToReport instanceof FileNotFoundException)) {
|
||||||
exceptionToReport = exceptionToReport.getCause();
|
exceptionToReport = exceptionToReport.getCause();
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2023 the original author or authors.
|
* Copyright 2012-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -166,6 +166,16 @@ class LoggingApplicationListenerTests {
|
||||||
assertThat(this.output).contains("Hello world").doesNotContain("???").startsWith("null ").endsWith("BOOTBOOT");
|
assertThat(this.output).contains("Hello world").doesNotContain("???").startsWith("null ").endsWith("BOOTBOOT");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@ClassPathExclusions("janino-*.jar")
|
||||||
|
void tryingToUseJaninoWhenItIsNotOnTheClasspathFailsGracefully(CapturedOutput output) {
|
||||||
|
addPropertiesToEnvironment(this.context, "logging.config=classpath:logback-janino.xml");
|
||||||
|
assertThatIllegalStateException()
|
||||||
|
.isThrownBy(() -> this.listener.initialize(this.context.getEnvironment(), this.context.getClassLoader()));
|
||||||
|
assertThat(output)
|
||||||
|
.contains("Logging system failed to initialize using configuration from 'classpath:logback-janino.xml'");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void trailingWhitespaceInLoggingConfigShouldBeTrimmed() {
|
void trailingWhitespaceInLoggingConfigShouldBeTrimmed() {
|
||||||
addPropertiesToEnvironment(this.context, "logging.config=classpath:logback-nondefault.xml ");
|
addPropertiesToEnvironment(this.context, "logging.config=classpath:logback-nondefault.xml ");
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<configuration>
|
||||||
|
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
|
<encoder>
|
||||||
|
<pattern>%property{LOG_FILE} [%t] ${PID:-????} %c{1}: %m%n BOOTBOOT</pattern>
|
||||||
|
</encoder>
|
||||||
|
<filter class="ch.qos.logback.core.filter.EvaluatorFilter">
|
||||||
|
<evaluator>
|
||||||
|
<expression>return level <= DEBUG;</expression>
|
||||||
|
</evaluator>
|
||||||
|
<OnMismatch>DENY</OnMismatch>
|
||||||
|
<OnMatch>NEUTRAL</OnMatch>
|
||||||
|
</filter>
|
||||||
|
</appender>
|
||||||
|
<root level="INFO">
|
||||||
|
<appender-ref ref="CONSOLE" />
|
||||||
|
</root>
|
||||||
|
</configuration>
|
||||||
Loading…
Reference in New Issue