From dd14158ad7fd4bae5263aa3229b9239187d10763 Mon Sep 17 00:00:00 2001 From: Yanming Zhou Date: Wed, 27 Nov 2024 16:36:26 +0800 Subject: [PATCH 1/2] Document how to use structured logging with custom log configuration See gh-43301 --- .../reference/pages/features/logging.adoc | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/features/logging.adoc b/spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/features/logging.adoc index bf2d7b5cca9..7fa0b1d1d39 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/features/logging.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/features/logging.adoc @@ -450,6 +450,34 @@ Spring Boot supports structured logging and has support for the following JSON f 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. +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. +Take `CONSOLE_LOG_STRUCTURED_FORMAT` for example: +[tabs] +====== +Logback:: ++ +[source,xml] +---- + + + ${CONSOLE_LOG_STRUCTURED_FORMAT} + ${CONSOLE_LOG_CHARSET} + +---- +Log4j2:: ++ +[source,xml] +---- + + +---- +====== +You can refer to default configurations in `spring-boot.jar` for fine-grained control: + +* {code-spring-boot}/spring-boot-project/spring-boot/src/main/resources/org/springframework/boot/logging/logback/structured-console-appender.xml[Logback Structured Console Appender] +* {code-spring-boot}/spring-boot-project/spring-boot/src/main/resources/org/springframework/boot/logging/logback/structured-file-appender.xml[Logback Structured File Appender] +* {code-spring-boot}/spring-boot-project/spring-boot/src/main/resources/org/springframework/boot/logging/log4j2/log4j2.xml[Log4j2 Console Appender] +* {code-spring-boot}/spring-boot-project/spring-boot/src/main/resources/org/springframework/boot/logging/log4j2/log4j2-file.xml[Log4j2 Console and File Appender] [[features.logging.structured.ecs]] From 2ff6dea5caf766cadf2696dc1e5b33b15982cf8d Mon Sep 17 00:00:00 2001 From: Moritz Halbritter Date: Thu, 5 Dec 2024 10:13:08 +0100 Subject: [PATCH 2/2] Polish "Document how to use structured logging with custom log configuration" See gh-43301 --- .../modules/reference/pages/features/logging.adoc | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/features/logging.adoc b/spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/features/logging.adoc index 7fa0b1d1d39..4af1cb20300 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/features/logging.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/features/logging.adoc @@ -464,6 +464,11 @@ Logback:: ${CONSOLE_LOG_CHARSET} ---- ++ +You can also refer to the default configurations included in Spring Boot: ++ +* {code-spring-boot}/spring-boot-project/spring-boot/src/main/resources/org/springframework/boot/logging/logback/structured-console-appender.xml[Logback Structured Console Appender] +* {code-spring-boot}/spring-boot-project/spring-boot/src/main/resources/org/springframework/boot/logging/logback/structured-file-appender.xml[Logback Structured File Appender] Log4j2:: + [source,xml] @@ -471,13 +476,12 @@ Log4j2:: ---- -====== -You can refer to default configurations in `spring-boot.jar` for fine-grained control: - -* {code-spring-boot}/spring-boot-project/spring-boot/src/main/resources/org/springframework/boot/logging/logback/structured-console-appender.xml[Logback Structured Console Appender] -* {code-spring-boot}/spring-boot-project/spring-boot/src/main/resources/org/springframework/boot/logging/logback/structured-file-appender.xml[Logback Structured File Appender] ++ +You can also refer to the default configurations included in Spring Boot: ++ * {code-spring-boot}/spring-boot-project/spring-boot/src/main/resources/org/springframework/boot/logging/log4j2/log4j2.xml[Log4j2 Console Appender] * {code-spring-boot}/spring-boot-project/spring-boot/src/main/resources/org/springframework/boot/logging/log4j2/log4j2-file.xml[Log4j2 Console and File Appender] +====== [[features.logging.structured.ecs]]