• spring-cloud-sleuth 1.2.0.RELEASE 使用


    导入依赖

    		<dependency>
    			<groupId>org.springframework.cloud</groupId>
    			<artifactId>spring-cloud-starter-sleuth</artifactId>
    			<version>1.2.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>
    

    获取当前id

    import org.springframework.cloud.sleuth.Tracer;
    
    @Service
    public class Breadcrumb {
    
      @Autowired
      private Tracer tracer;
    
      public String breadcrumbId() {
        return tracer.getCurrentSpan().traceIdString();
      }
    }
    
  • 相关阅读:
    【CLR Via C#】2 程序集
    值类型与引用类型
    .Net Framework简介
    【CLR Via C#】15 枚举类型与位类型
    Dictionary的用法及用途
    枚举
    GitExtensions使用教程
    Bootstrap如何禁止响应式布局
    【StyleCop】StyleCop规则汇总
    优化SQL查询:如何写出高性能SQL语句
  • 原文地址:https://www.cnblogs.com/chenglc/p/12109277.html
Copyright © 2020-2023  润新知