Skip to content

Commit

Permalink
feat($Sleuth): record trance ID and span ID in logs
Browse files Browse the repository at this point in the history
Log pattern be like: [${APPLICATION},%X{traceId},%X{spanId}]

BREAKING CHANGE: support trace ID and span ID in logs
  • Loading branch information
johnnymillergh committed Feb 27, 2022
1 parent 497bb1e commit a3f4811
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- The complete logback manual documents the latest version of logback framework at https://logback.qos.ch/manual/ -->
<!-- https://docs.spring.io/spring-cloud-sleuth/docs/current/reference/html/project-features.html#features-log-integration-json-logback -->
<included>
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<springProperty scope="context" name="APPLICATION" source="spring.application.name"/>
<jmxConfigurator/>

<!-- Converter Class Configuration -->
Expand All @@ -10,11 +12,17 @@
converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter"/>

<!-- Log Render Configuration -->
<springProperty scope="context" name="APPLICATION" source="spring.application.name"/>
<!--
Spring Cloud Sleuth adds two types of IDs to your logging, one called a trace ID and the other called a span ID.
The span ID represents a basic unit of work, for example sending an HTTP request. The trace ID contains a set of span IDs,
forming a tree-like structure. The trace ID will remain the same as one microservice calls the next.
https://dzone.com/articles/tracing-in-microservices-with-spring-cloud-sleuth#:~:text=Spring%20Cloud%20Sleuth%20adds%20two,forming%20a%20tree%2Dlike%20structure.
-->
<property name="CONSOLE_LOG_PATTERN"
value="%d{yyyy-MM-dd HH:mm:ss.SSS} %clr(%5p) %clr(${PID:- }){magenta} - [%15.15t] %-48.48logger{48} : %msg%n%wEx"/>
value="%d{yyyy-MM-dd HH:mm:ss.SSS} %clr(%5p) %clr([${APPLICATION},%X{traceId},%X{spanId}]){yellow} %clr(${PID:- }){magenta} - [%15.15t] %-48.48logger{48} : %msg%n%wEx"/>
<property name="FILE_LOG_PATTERN"
value="%d{yyyy-MM-dd HH:mm:ss.SSS} %5p ${PID:- } - [%t] %-48.48logger{48} : %msg%n%wEx"/>
value="%d{yyyy-MM-dd HH:mm:ss.SSS} %5p [${APPLICATION},%X{traceId},%X{spanId}] ${PID:- } - [%t] %-48.48logger{48} : %msg%n%wEx"/>
<!-- Log home is nothing related with Spring profiles or environments -->
<property name="LOG_HOME" value="logs"/>

Expand Down

0 comments on commit a3f4811

Please sign in to comment.