tlog implements link tracking

tlog implements link tracking

TLog completes log tracking of enterprise-level microservices by labeling logs. It does not collect logs, is simple to use, and generates a globally unique tracking code. In addition to tracking codes, TLog also supports the addition of SpanId and upstream and downstream service information labels. You can also customize method-level tags to make locating logs a breeze

Integrate springboot

rely

 <dependency>
            <groupId>com.yomahub</groupId>
            <artifactId>tlog-all-spring-boot-starter</artifactId>
            <version>1.5.0</version>
        </dependency>

control layer

package com.tlog.springboottlog.controller;

import com.tlog.springboottlog.config.TlogConvert;
import com.yomahub.tlog.core.annotation.TLogAspect;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author 蔡定努
 * @date 2023/09/06 12:59
 */
@Slf4j
@RestController
public class TestController {
    
    
    @GetMapping("request")
    public void aa(HttpServletRequest request) {
    
    
        log.info("--------完成--------------");
    }


    /**
     * 默认方式
     *
     * @author 蔡定努
     */
    @GetMapping("b")
    public void b() {
    
    
        log.info("默认方式");
    }


    /**
     * 注解带参数
     *
     * @author 蔡定努
     */
    @GetMapping("aspect")
    @TLogAspect(value = {
    
    "id", "name"}, pattern = "<-{}->", joint = "_")
    public void aspect(String id, String name) {
    
    
        log.info("加了patter和joint的示例");
    }


    /**
     * 注解,自己拼接链路
     *
     * @author 蔡定努
     */
    @GetMapping("aspect2")
    @TLogAspect(convert = TlogConvert.class)
    public void aspect2(String id, String name) {
    
    
        log.info("加了patter和joint的示例");
    }


}

logback-spring.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false">
    <property name="LOG_HOME" value="./logs" />
    <springProperty scop="context" name="APP_NAME" source="spring.application.name" defaultValue=""/>
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <!--这里替换成AspectLogbackEncoder-->
        <encoder class="com.yomahub.tlog.core.enhance.logback.AspectLogbackEncoder">
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
        </encoder>
    </appender>
    <appender name="FILE"  class="ch.qos.logback.core.rolling.RollingFileAppender">
        <File>${LOG_HOME}/${APP_NAME}.log</File>
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <FileNamePattern>${LOG_HOME}/${APP_NAME}.log.%d{yyyy-MM-dd}.%i.log</FileNamePattern>
            <MaxHistory>30</MaxHistory>
            <maxFileSize>1000MB</maxFileSize>
        </rollingPolicy>
        <!--这里替换成AspectLogbackEncoder-->
        <encoder class="com.yomahub.tlog.core.enhance.logback.AspectLogbackEncoder">
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
        </encoder>
    </appender>

    <root level="INFO">
        <appender-ref ref="STDOUT" />
        <appender-ref ref="FILE" />
    </root>
</configuration>

If you need to print the interface time, add the configuration in the configuration file

tlog.enable-invoke-time-print=on

Effect:

image-20230906133247454

Guess you like

Origin blog.csdn.net/caidingnu/article/details/132713432