You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* pr/32578:
Document Log4j2 extensions
* Merge pull request for #32735:
Polish 'Resolve URLs using Log4J2 mechanisms'
Resolve URLs using Log4j2 mechanisms
* Merge pull request for #32734:
Polish 'Support profile specific Log4j2 configuration'
Support profile specific Log4j2 configuration
* Merge pull request for #32733:
Polish 'Add Log4J2 PropertySource backed by the Spring Environment'
Add Log4J2 PropertySource backed by the Spring Environment
* Merge pull request for #32732:
Polish 'Support Log4J2 string lookups from the Spring Environment'
Support Log4J2 string lookups from the Spring Environment
* Merge pull request for #32730:
Polish 'Add Spring Environment to LoggerContext'
Add Spring Environment to LoggerContext
* Merge pull request for #32730:
Polish 'Support 'log4j.configurationFile' system property'
Support 'log4j.configurationFile' system property
Closesgh-32578
Copy file name to clipboardExpand all lines: spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/logging.adoc
+76-3
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
[[features.logging]]
2
2
== Logging
3
3
Spring Boot uses https://commons.apache.org/logging[Commons Logging] for all internal logging but leaves the underlying log implementation open.
4
-
Default configurations are provided for {java-api}/java/util/logging/package-summary.html[Java Util Logging], https://logging.apache.org/log4j/2.x/[Log4J2], and https://logback.qos.ch/[Logback].
4
+
Default configurations are provided for {java-api}/java/util/logging/package-summary.html[Java Util Logging], https://logging.apache.org/log4j/2.x/[Log4j2], and https://logback.qos.ch/[Logback].
5
5
In each case, loggers are pre-configured to use console output with optional file output also available.
6
6
7
7
By default, if you use the "`Starters`", Logback is used for logging.
@@ -158,7 +158,7 @@ As a result, specific configuration keys (such as `logback.configurationFile` fo
158
158
[[features.logging.file-rotation]]
159
159
=== File Rotation
160
160
If you are using the Logback, it is possible to fine-tune log rotation settings using your `application.properties` or `application.yaml` file.
161
-
For all other logging system, you will need to configure rotation settings directly yourself (for example, if you use Log4J2 then you could add a `log4j2.xml` or `log4j2-spring.xml` file).
161
+
For all other logging system, you will need to configure rotation settings directly yourself (for example, if you use Log4j2 then you could add a `log4j2.xml` or `log4j2-spring.xml` file).
162
162
163
163
The following rotation policy properties are supported:
164
164
@@ -433,7 +433,7 @@ Profile sections are supported anywhere within the `<configuration>` element.
433
433
Use the `name` attribute to specify which profile accepts the configuration.
434
434
The `<springProfile>` tag can contain a profile name (for example `staging`) or a profile expression.
435
435
A profile expression allows for more complicated profile logic to be expressed, for example `production & (eu-central | eu-west)`.
436
-
Check the {spring-framework-docs}/core.html#beans-definition-profiles-java[reference guide] for more details.
436
+
Check the {spring-framework-docs}/core.html#beans-definition-profiles-java[Spring Framework reference guide] for more details.
437
437
The following listing shows three sample profiles:
438
438
439
439
[source,xml,subs="verbatim",indent=0]
@@ -475,3 +475,76 @@ The following example shows how to expose properties for use within Logback:
475
475
476
476
NOTE: The `source` must be specified in kebab case (such as `my.property-name`).
477
477
However, properties can be added to the `Environment` by using the relaxed rules.
478
+
479
+
480
+
481
+
[[features.logging.log4j2-extensions]]
482
+
=== Log4j2 Extensions
483
+
Spring Boot includes a number of extensions to Log4j2 that can help with advanced configuration.
484
+
You can use these extensions in any `log4j2-spring.xml` configuration file.
485
+
486
+
NOTE: Because the standard `log4j2.xml` configuration file is loaded too early, you cannot use extensions in it.
487
+
You need to either use `log4j2-spring.xml` or define a configprop:logging.config[] property.
488
+
489
+
NOTE: The extensions supersede the https://logging.apache.org/log4j/2.x/log4j-spring-boot/index.html[Spring Boot support] provided by Log4J.
490
+
You should make sure not include the `org.apache.logging.log4j:log4j-spring-boot` module in your build.
If you want to refer to properties from your Spring `Environment` within your Log4j2 configuration you can use `spring:` prefixed https://logging.apache.org/log4j/2.x/manual/lookups.html[lookups].
524
+
Doing so can be useful if you want to access values from your `application.properties` file in your Log4j2 configuration.
525
+
526
+
The following example shows how to set a Log4j2 property named `applicationName` that reads `spring.application.name` from the Spring `Environment`:
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.
542
+
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.
543
+
544
+
All system properties that are loaded after the Log4J initialization can be obtained from the Spring `Environment`.
545
+
For example, you could add `log4j2.skipJansi=false` to your `application.properties` file to have the `ConsoleAppender` use a Jansi on Windows.
546
+
547
+
NOTE: The Spring `Environment` is only considered when system properties and OS environment variables do not contain the value being loaded.
548
+
549
+
WARNING: System properties that are loaded during early Log4j2 initialization cannot reference the Spring `Environment`.
550
+
For example, the property Log4j2 uses to allow the default Log4j2 implementation to be chosen is used before the Spring Environment is available.
Copy file name to clipboardExpand all lines: spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/Log4J2LoggingSystem.java
0 commit comments