Skip to content

Commit dd14158

Browse files
quaffmhalbritter
authored andcommitted
Document how to use structured logging with custom log configuration
See gh-43301
1 parent b7f3627 commit dd14158

File tree

1 file changed

+28
-0
lines changed
  • spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/features

1 file changed

+28
-0
lines changed

spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/features/logging.adoc

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,34 @@ Spring Boot supports structured logging and has support for the following JSON f
450450

451451
To enable structured logging, set the property configprop:logging.structured.format.console[] (for console output) or configprop:logging.structured.format.file[] (for file output) to the id of the format you want to use.
452452

453+
If you are using xref:#features.logging.custom-log-configuration[Custom Log Configuration], update your configuration to respect `CONSOLE_LOG_STRUCTURED_FORMAT` and `FILE_LOG_STRUCTURED_FORMAT` system properties.
454+
Take `CONSOLE_LOG_STRUCTURED_FORMAT` for example:
455+
[tabs]
456+
======
457+
Logback::
458+
+
459+
[source,xml]
460+
----
461+
<!-- replace your encoder with StructuredLogEncoder -->
462+
<encoder class="org.springframework.boot.logging.logback.StructuredLogEncoder">
463+
<format>${CONSOLE_LOG_STRUCTURED_FORMAT}</format>
464+
<charset>${CONSOLE_LOG_CHARSET}</charset>
465+
</encoder>
466+
----
467+
Log4j2::
468+
+
469+
[source,xml]
470+
----
471+
<!-- replace your PatternLayout with StructuredLogLayout -->
472+
<StructuredLogLayout format="${sys:CONSOLE_LOG_STRUCTURED_FORMAT}" charset="${sys:CONSOLE_LOG_CHARSET}"/>
473+
----
474+
======
475+
You can refer to default configurations in `spring-boot.jar` for fine-grained control:
476+
477+
* {code-spring-boot}/spring-boot-project/spring-boot/src/main/resources/org/springframework/boot/logging/logback/structured-console-appender.xml[Logback Structured Console Appender]
478+
* {code-spring-boot}/spring-boot-project/spring-boot/src/main/resources/org/springframework/boot/logging/logback/structured-file-appender.xml[Logback Structured File Appender]
479+
* {code-spring-boot}/spring-boot-project/spring-boot/src/main/resources/org/springframework/boot/logging/log4j2/log4j2.xml[Log4j2 Console Appender]
480+
* {code-spring-boot}/spring-boot-project/spring-boot/src/main/resources/org/springframework/boot/logging/log4j2/log4j2-file.xml[Log4j2 Console and File Appender]
453481

454482

455483
[[features.logging.structured.ecs]]

0 commit comments

Comments
 (0)