From ba0f6ce6be4a7712879b8adfef322304fffa98e6 Mon Sep 17 00:00:00 2001
From: buildmaster
Often you do not want to store your logs in a text file but in a JSON file that Logstash can immediately pick. To do that you have to do the following (for readability
-we’re passing the dependencies in the groupId:artifactId:version notation.
Dependencies setup
ch.qos.logback:logback-core)4.6 : net.logstash.logback:logstash-logback-encoder:4.6Logback setup
Below you can find an example of a Logback configuration (file named logback-spring.xml) that:
build/${spring.application.name}.json fileUnresolved directive in intro.adoc - include::https://raw.githubusercontent.com/spring-cloud-samples/sleuth-documentation-apps/master/service1/src/main/resources/logback-spring.xml[]
![]() | Note | ||||||||
|---|---|---|---|---|---|---|---|---|---|
If you’re using a custom Dependencies setup
Logback setup Below you can find an example of a Logback configuration (file named logback-spring.xml) that:
<?xml version="1.0" encoding="UTF-8"?> +<configuration> + <include resource="org/springframework/boot/logging/logback/defaults.xml"/> + + <springProperty scope="context" name="springAppName" source="spring.application.name"/> + <!-- Example for logging into the build folder of your project --> + <property name="LOG_FILE" value="${BUILD_FOLDER:-build}/${springAppName}"/> + + <!-- You can override this to have a custom pattern --> + <property name="CONSOLE_LOG_PATTERN" + value="%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}"/> + + <!-- Appender to log to console --> + <appender name="console" class="ch.qos.logback.core.ConsoleAppender"> + <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> + <!-- Minimum logging level to be presented in the console logs--> + <level>DEBUG</level> + </filter> + <encoder> + <pattern>${CONSOLE_LOG_PATTERN}</pattern> + <charset>utf8</charset> + </encoder> + </appender> + + <!-- Appender to log to file --> + <appender name="flatfile" class="ch.qos.logback.core.rolling.RollingFileAppender"> + <file>${LOG_FILE}</file> + <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> + <fileNamePattern>${LOG_FILE}.%d{yyyy-MM-dd}.gz</fileNamePattern> + <maxHistory>7</maxHistory> + </rollingPolicy> + <encoder> + <pattern>${CONSOLE_LOG_PATTERN}</pattern> + <charset>utf8</charset> + </encoder> + </appender> + + <!-- Appender to log to file in a JSON format --> + <appender name="logstash" class="ch.qos.logback.core.rolling.RollingFileAppender"> + <file>${LOG_FILE}.json</file> + <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> + <fileNamePattern>${LOG_FILE}.json.%d{yyyy-MM-dd}.gz</fileNamePattern> + <maxHistory>7</maxHistory> + </rollingPolicy> + <encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder"> + <providers> + <timestamp> + <timeZone>UTC</timeZone> + </timestamp> + <pattern> + <pattern> + { + "severity": "%level", + "service": "${springAppName:-}", + "trace": "%X{X-B3-TraceId:-}", + "span": "%X{X-B3-SpanId:-}", + "parent": "%X{X-B3-ParentSpanId:-}", + "exportable": "%X{X-Span-Export:-}", + "pid": "${PID:-}", + "thread": "%thread", + "class": "%logger{40}", + "rest": "%message" + } + </pattern> + </pattern> + </providers> + </encoder> + </appender> + + <root level="INFO"> + <appender-ref ref="console"/> + <!-- uncomment this to have also JSON logs --> + <!--<appender-ref ref="logstash"/>--> + <!--<appender-ref ref="flatfile"/>--> + </root> +</configuration>
The span context is the state that must get propagated to any child Spans across process boundaries. Part of the Span Context is the Baggage. The trace and span IDs are a required part of the span context. Baggage is an optional part. Baggage is a set of key:value pairs stored in the span context. Baggage travels together with the trace diff --git a/1.3.x/single/spring-cloud-sleuth.html b/1.3.x/single/spring-cloud-sleuth.html index 737bc6bc5..735ab578a 100644 --- a/1.3.x/single/spring-cloud-sleuth.html +++ b/1.3.x/single/spring-cloud-sleuth.html @@ -46,7 +46,82 @@ Kibana would look like this: Often you do not want to store your logs in a text file but in a JSON file that Logstash can immediately pick. To do that you have to do the following (for readability
-we’re passing the dependencies in the Dependencies setup
Logback setup Below you can find an example of a Logback configuration (file named logback-spring.xml) that:
Unresolved directive in intro.adoc - include::https://raw.githubusercontent.com/spring-cloud-samples/sleuth-documentation-apps/master/service1/src/main/resources/logback-spring.xml[]
|