• spring-cloud-sleuth 2.0.0.RELEASE 使用


    导入依赖

            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-sleuth</artifactId>
                <version>2.0.0.RELEASE</version>
            </dependency>
    

    日志

    <configuration>
        <!-- TraceId:%X{X-B3-TraceId:-} SpanId:%X{X-B3-SpanId:-}-->
        <property name="CONSOLE_LOG_PATTERN"
                  value="%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level [traceId= %X{X-B3-TraceId:-}] [SpanId= %X{X-B3-SpanId:-}] %logger{5} - %msg%n"/>
    
        <appender name="rollingAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
            <file>${LOG_PATH}/billmanager.log</file>
            <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
                <fileNamePattern>/logs/heuristic-%d{yyyy-MM-dd}.log</fileNamePattern>
                <maxHistory>30</maxHistory>
            </rollingPolicy>
            <!-- 必须指定,否则不会往文件输出内容 -->
            <encoder>
                <pattern>${CONSOLE_LOG_PATTERN}</pattern>
                <charset>utf8</charset>
            </encoder>
            <append>false</append>
            <prudent>false</prudent>
        </appender>
    
        <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
            <encoder>
                <pattern>${CONSOLE_LOG_PATTERN}</pattern>
                <charset>utf8</charset>
            </encoder>
        </appender>
    
    
        <root level="info">
            <appender-ref ref="STDOUT"/>
            <appender-ref ref="rollingAppender"/>
        </root>
       
    
    </configuration>
    

    获取当前的traceId

    import brave.Tracer;
    
    @Service
    public class Breadcrumb {
    
      @Autowired
      private Tracer tracer;
    
      public String breadcrumbId() {
        return tracer.currentSpan().context().traceIdString();
      }
    }
    
  • 相关阅读:
    JSON.parse()与JSON.stringify()的区别
    响应式布局
    document.selection
    jQuery $.proxy() 方法
    <转> 键值表
    jquery-jqzoom 插件 用例
    jquery 笔记
    前端表单验证常用的15个JS正则表达式<转>
    css 问题解决
    <转>break与continue
  • 原文地址:https://www.cnblogs.com/chenglc/p/12109280.html
Copyright © 2020-2023  润新知