SkyWalking集成logback

1.引入skywalking的jar包,导入的包和agent版本一致

        
            org.apache.skywalking
            apm-toolkit-trace
            8.12.0
        
        
            org.apache.skywalking
            apm-toolkit-opentracing
            8.12.0
        
        
            org.apache.skywalking
            apm-toolkit-logback-1.x
            8.12.0
        

2.修改logback.xml



    
    
    

    
    :ss} %-5level
    ${springAppName:-} %thread %logger %msg%n"/>

    
    
        
            
                ${log.pattern}
            
        
    

    
    
        ${log.path}/info.log
        
        
            
            ${log.path}/info.%d{yyyy-MM-dd}-%i.log
            
            3
            
            100MB
            
            200MB
            
            true
        
        
            
                ${log.pattern}
            
        
        
            
            info
            
            ACCEPT
            
            DENY
        
    

    
        ${log.path}/error.log
        
        
            
            ${log.path}/error.%d{yyyy-MM-dd}-%i.log
            
            3
            
            100MB
            
            200MB
            
            true
        
        
            
                ${log.pattern}
            
        
        
            
            error
            
            ACCEPT
            
            DENY
        
    

    
    
        
            
                ${log.pattern}
            
        
    

    
    
        
        
        
        
    


看到日志打印出TID则表示配置成功

3.自定义标签快速定位异常

    private final Tracer tracer = new SkywalkingTracer();

    private void setSkywalkingTagErrMsg(String msg, String code) {
        ActiveSpan span = tracer.activeSpan();
        span.setTag("error.msg", msg);
        span.setTag("error.code", code);
    }

你可能感兴趣的:(skywalking,skywalking,logback,java)