diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/logging.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/logging.adoc index 0d48f2e534..b49961c553 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/logging.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/logging.adoc @@ -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. diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/SpringEnvironmentLookup.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/SpringEnvironmentLookup.java index 71889db912..48989abfc3 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/SpringEnvironmentLookup.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/SpringEnvironmentLookup.java @@ -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 diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/SpringProfileArbiter.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/SpringProfileArbiter.java index f002813dce..6aa7f5421a 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/SpringProfileArbiter.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/SpringProfileArbiter.java @@ -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 { + static final class Builder implements org.apache.logging.log4j.core.util.Builder { 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; } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/Log4J2LoggingSystemTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/Log4J2LoggingSystemTests.java index df099a8cca..3283e27f49 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/Log4J2LoggingSystemTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/Log4J2LoggingSystemTests.java @@ -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"); } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/SpringEnvironmentLookupTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/SpringEnvironmentLookupTests.java index e3f7a5e175..33a85d34d0 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/SpringEnvironmentLookupTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/SpringEnvironmentLookupTests.java @@ -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"); } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/SpringProfileArbiterTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/SpringProfileArbiterTests.java index ab1f6e746a..e27a1e4cdb 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/SpringProfileArbiterTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/SpringProfileArbiterTests.java @@ -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; } } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/TestLog4J2LoggingSystem.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/TestLog4J2LoggingSystem.java index 43cd1a6760..cc945ae690 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/TestLog4J2LoggingSystem.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/TestLog4J2LoggingSystem.java @@ -25,7 +25,7 @@ import org.apache.logging.log4j.core.config.Configuration; class TestLog4J2LoggingSystem extends Log4J2LoggingSystem { - private List availableClasses = new ArrayList<>(); + private final List availableClasses = new ArrayList<>(); TestLog4J2LoggingSystem() { super(TestLog4J2LoggingSystem.class.getClassLoader());