gitee.com/quant1x/gox@v1.21.2/logger/logger_test.go (about)

     1  package logger
     2  
     3  import (
     4  	"fmt"
     5  	"gitee.com/quant1x/gox/api"
     6  	"gitee.com/quant1x/gox/gls"
     7  	"gitee.com/quant1x/gox/mdc"
     8  	"gitee.com/quant1x/pkg/uuid"
     9  	"runtime"
    10  	"testing"
    11  	"time"
    12  )
    13  
    14  func TestGoId(t *testing.T) {
    15  	buf := make([]byte, 1024)
    16  	runtime.Stack(buf, false)
    17  	text := api.Bytes2String(buf)
    18  	fmt.Println(text)
    19  }
    20  
    21  func TestLogger(t *testing.T) {
    22  	SetLogPath("/opt/logs/test")
    23  	u1 := uuid.NewV4()
    24  	defer gls.DeleteGls(gls.GoID())
    25  	mdc.Set(mdc.APP_TRACEID, u1.String())
    26  	//logger := api.GetLogger("test1")
    27  	//SetConsole()
    28  	for i := 0; i < 200; i++ {
    29  		Infof("info-%d", i)
    30  		time.Sleep(time.Millisecond * 1)
    31  	}
    32  	Infof("测试中文\n")
    33  	Debug("debug")
    34  	Error("error")
    35  	Warn("warn")
    36  	Info("测试中文")
    37  	fmt.Println("ok")
    38  	Fatal("xxx")
    39  	//logger.FlushLogger()
    40  	FlushLogger()
    41  	mdc.Remove(mdc.APP_TRACEID)
    42  }