Skip to content

Commit c9921b8

Browse files
committed
Merge pull request #43301 from quaff
* pr/43301: Polish "Document how to use structured logging with custom log configuration" Document how to use structured logging with custom log configuration Closes gh-43301
2 parents b7f3627 + 2ff6dea commit c9921b8

File tree

1 file changed

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

1 file changed

+32
-0
lines changed

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,38 @@ 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+
+
468+
You can also refer to the default configurations included in Spring Boot:
469+
+
470+
* {code-spring-boot}/spring-boot-project/spring-boot/src/main/resources/org/springframework/boot/logging/logback/structured-console-appender.xml[Logback Structured Console Appender]
471+
* {code-spring-boot}/spring-boot-project/spring-boot/src/main/resources/org/springframework/boot/logging/logback/structured-file-appender.xml[Logback Structured File Appender]
472+
Log4j2::
473+
+
474+
[source,xml]
475+
----
476+
<!-- replace your PatternLayout with StructuredLogLayout -->
477+
<StructuredLogLayout format="${sys:CONSOLE_LOG_STRUCTURED_FORMAT}" charset="${sys:CONSOLE_LOG_CHARSET}"/>
478+
----
479+
+
480+
You can also refer to the default configurations included in Spring Boot:
481+
+
482+
* {code-spring-boot}/spring-boot-project/spring-boot/src/main/resources/org/springframework/boot/logging/log4j2/log4j2.xml[Log4j2 Console Appender]
483+
* {code-spring-boot}/spring-boot-project/spring-boot/src/main/resources/org/springframework/boot/logging/log4j2/log4j2-file.xml[Log4j2 Console and File Appender]
484+
======
453485

454486

455487
[[features.logging.structured.ecs]]

0 commit comments

Comments
 (0)