Spring Boot Tutorial 0/110 lessons ~6 min read Lesson 84
Production Logging
Production logs are read by machines: a JSON log shape, shipped to Loki / CloudWatch / Datadog, queryable by trace ID.
Course progress0%
Focus
2 guided sections
Practice signal
Examples included
Career prep
Foundation builder
Introduction
Production logs are read by machines: a JSON log shape, shipped to Loki / CloudWatch / Datadog, queryable by trace ID. Plaintext logs are useless at scale.
Informative example
bash
# pom.xml<dependency><groupId>net.logstash.logback</groupId><artifactId>logstash-logback-encoder</artifactId></dependency># logback-spring.xml<configuration><springProfile name="prod"><appender name="JSON" class="ch.qos.logback.core.ConsoleAppender"><encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder"><providers><pattern><pattern>{ "service":"${spring.application.name}","trace":"%mdc{traceId}", "span":"%mdc{spanId}" }</pattern></pattern><timestamp/><logLevel/><loggerName/><message/><stackTrace/></providers></encoder></appender><root level="INFO"><appender-ref ref="JSON"/></root></springProfile></configuration>
Ready to mark this lesson complete?Track your journey across the entire course.