Structured logging in Spring B... Note
Spring

Structured logging in Spring Boot 3.4

Structured logging, an integral part of troubleshooting applications, involves writing log output in a machine-readable format, such as JSON. Spring Boot 3.4 supports structured logging out of the box, using formats like Elastic Common Schema (ECS) and Logstash. Enabling structured logging for the console can be done by setting the logging.structured.format.console property in application.properties.To enable structured logging to a file, set the logging.structured.format.file and logging.file.name properties. Developers can add additional fields to log events in a structured way, such as the user id, using the Mapped Diagnostic Context (MDC) or the fluent logging API.Spring Boot provides built-in support for specific fields like service name and version, which can be set in application.properties. Custom log formats can be implemented by creating a class that implements the StructuredLogFormatter interface and referencing it in the application.properties file.A custom JSON formatter can be created using the new JsonWriter in Spring Boot 3.4, which simplifies the process of generating JSON-formatted log messages. The documentation for structured logging in Spring Boot has been updated to reflect these new features. Feedback and bug reports are welcomed through the issue tracker.