mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-07-05 00:56:58 +08:00
Merge pull request #32742 from izeye
* gh-32742: Polish Log4j2 changes Closes gh-32742
This commit is contained in:
commit
3c061dc49b
@ -487,7 +487,7 @@ NOTE: Because the standard `log4j2.xml` configuration file is loaded too early,
|
||||
You need to either use `log4j2-spring.xml` or define a configprop:logging.config[] property.
|
||||
|
||||
NOTE: The extensions supersede the https://logging.apache.org/log4j/2.x/log4j-spring-boot/index.html[Spring Boot support] provided by Log4J.
|
||||
You should make sure not include the `org.apache.logging.log4j:log4j-spring-boot` module in your build.
|
||||
You should make sure not to include the `org.apache.logging.log4j:log4j-spring-boot` module in your build.
|
||||
|
||||
|
||||
|
||||
@ -536,12 +536,12 @@ NOTE: The lookup key should be specified in kebab case (such as `my.property-nam
|
||||
|
||||
|
||||
|
||||
[[features.logging.log4j2-extensions.environment-peroperty-source]]
|
||||
[[features.logging.log4j2-extensions.environment-property-source]]
|
||||
==== Log4j2 System Properties
|
||||
Log4j2 supports a number of https://logging.apache.org/log4j/2.x/manual/configuration.html#SystemProperties[System Properties] that can be used configure various items.
|
||||
Log4j2 supports a number of https://logging.apache.org/log4j/2.x/manual/configuration.html#SystemProperties[System Properties] that can be used to configure various items.
|
||||
For example, the `log4j2.skipJansi` system property can be used to configure if the `ConsoleAppender` will try to use a https://github.com/fusesource/jansi[Jansi] output stream on Windows.
|
||||
|
||||
All system properties that are loaded after the Log4J initialization can be obtained from the Spring `Environment`.
|
||||
All system properties that are loaded after the Log4j2 initialization can be obtained from the Spring `Environment`.
|
||||
For example, you could add `log4j2.skipJansi=false` to your `application.properties` file to have the `ConsoleAppender` use a Jansi on Windows.
|
||||
|
||||
NOTE: The Spring `Environment` is only considered when system properties and OS environment variables do not contain the value being loaded.
|
||||
|
@ -44,7 +44,7 @@ class SpringEnvironmentLookup implements LoggerContextAware, StrLookup {
|
||||
@Override
|
||||
public String lookup(String key) {
|
||||
Assert.state(this.environment != null, "Unable to obtain Spring Environment from LoggerContext");
|
||||
return (this.environment != null) ? this.environment.getProperty(key) : null;
|
||||
return this.environment.getProperty(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -64,7 +64,7 @@ final class SpringProfileArbiter implements Arbiter {
|
||||
/**
|
||||
* Standard Builder to create the Arbiter.
|
||||
*/
|
||||
public static final class Builder implements org.apache.logging.log4j.core.util.Builder<SpringProfileArbiter> {
|
||||
static final class Builder implements org.apache.logging.log4j.core.util.Builder<SpringProfileArbiter> {
|
||||
|
||||
private static final Logger statusLogger = StatusLogger.getLogger();
|
||||
|
||||
@ -86,7 +86,7 @@ final class SpringProfileArbiter implements Arbiter {
|
||||
* @return this
|
||||
* @see Profiles#of(String...)
|
||||
*/
|
||||
public Builder setName(String name) {
|
||||
Builder setName(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
@ -463,11 +463,10 @@ class Log4J2LoggingSystemTests extends AbstractLoggingSystemTests {
|
||||
|
||||
@Test
|
||||
void initializeAddsSpringEnvironmentPropertySource() {
|
||||
PropertiesUtil properties = PropertiesUtil.getProperties();
|
||||
this.environment.setProperty("spring", "boot");
|
||||
this.loggingSystem.beforeInitialize();
|
||||
this.loggingSystem.initialize(this.initializationContext, null, null);
|
||||
properties = PropertiesUtil.getProperties();
|
||||
PropertiesUtil properties = PropertiesUtil.getProperties();
|
||||
assertThat(properties.getStringProperty("spring")).isEqualTo("boot");
|
||||
}
|
||||
|
||||
|
@ -68,7 +68,7 @@ class SpringEnvironmentLookupTests {
|
||||
void lookupWhenNoSpringEnvironmentThrowsException() {
|
||||
this.loggerContext.removeObject(Log4J2LoggingSystem.ENVIRONMENT_KEY);
|
||||
Interpolator lookup = createLookup(this.loggerContext);
|
||||
assertThatIllegalStateException().isThrownBy(() -> assertThat(lookup.lookup("spring:test")).isEqualTo("test"))
|
||||
assertThatIllegalStateException().isThrownBy(() -> lookup.lookup("spring:test"))
|
||||
.withMessage("Unable to obtain Spring Environment from LoggerContext");
|
||||
}
|
||||
|
||||
|
@ -154,9 +154,7 @@ class SpringProfileArbiterTests {
|
||||
|
||||
private String getPackageResource(String fileName) {
|
||||
String path = ClassUtils.getPackageName(getClass());
|
||||
path = path.replace('.', '/');
|
||||
path = path + "/" + fileName;
|
||||
return "src/test/resources/" + path;
|
||||
return "src/test/resources/" + path.replace('.', '/') + "/" + fileName;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ import org.apache.logging.log4j.core.config.Configuration;
|
||||
|
||||
class TestLog4J2LoggingSystem extends Log4J2LoggingSystem {
|
||||
|
||||
private List<String> availableClasses = new ArrayList<>();
|
||||
private final List<String> availableClasses = new ArrayList<>();
|
||||
|
||||
TestLog4J2LoggingSystem() {
|
||||
super(TestLog4J2LoggingSystem.class.getClassLoader());
|
||||
|
Loading…
Reference in New Issue
Block a user