Improve exception message to hint that you might need a '-spring' file
See gh-42405
This commit is contained in:
committed by
Phillip Webb
parent
9b72e1f506
commit
86ce051bb5
@@ -43,7 +43,10 @@ class SpringEnvironmentLookup implements LoggerContextAware, StrLookup {
|
||||
|
||||
@Override
|
||||
public String lookup(String key) {
|
||||
Assert.state(this.environment != null, "Unable to obtain Spring Environment from LoggerContext");
|
||||
Assert.state(this.environment != null,
|
||||
"Unable to obtain Spring Environment from LoggerContext. "
|
||||
+ "This can happen if your log4j2 configuration filename does not end with '-spring' "
|
||||
+ "(for example using 'log4j2.xml' instead of 'log4j2-spring.xml')");
|
||||
return this.environment.getProperty(key);
|
||||
}
|
||||
|
||||
|
||||
@@ -69,7 +69,9 @@ class SpringEnvironmentLookupTests {
|
||||
this.loggerContext.removeObject(Log4J2LoggingSystem.ENVIRONMENT_KEY);
|
||||
Interpolator lookup = createLookup(this.loggerContext);
|
||||
assertThatIllegalStateException().isThrownBy(() -> lookup.lookup("spring:test"))
|
||||
.withMessage("Unable to obtain Spring Environment from LoggerContext");
|
||||
.withMessage("Unable to obtain Spring Environment from LoggerContext. "
|
||||
+ "This can happen if your log4j2 configuration filename does not end with '-spring' "
|
||||
+ "(for example using 'log4j2.xml' instead of 'log4j2-spring.xml')");
|
||||
}
|
||||
|
||||
private Interpolator createLookup(LoggerContext context) {
|
||||
|
||||
Reference in New Issue
Block a user