github.com/jtzjtz/kit@v1.0.2/log/logger_test.go (about) 1 package log 2 3 import ( 4 "github.com/gin-gonic/gin" 5 "net/http" 6 "testing" 7 "time" 8 ) 9 10 func TestLogInfo(t *testing.T) { 11 12 InitLogger("kit", "/Users/jtz/logs", 4, 100) 13 var info InfoEntity 14 info.Msg = "测试info日志" 15 info.Data = "infokk;k;" 16 ctx := new(gin.Context) 17 ctx.Request = new(http.Request) 18 ctx.Request.Header = http.Header{} 19 ctx.Request.Header.Set("TraceId", time.Now().String()) 20 LogInfo(info, ctx) 21 time.Sleep(1 * time.Second) 22 23 } 24 25 func TestLogError(t *testing.T) { 26 27 InitLogger("kit", "/Users/jtz/logs", 4, 100) 28 var errorInfo ErrEntity 29 errorInfo.Msg = "测试ERROR日志" 30 errorInfo.TraceId = "3534535345345" 31 //errorInfo.Data = nil 32 33 LogError(errorInfo, nil) 34 35 time.Sleep(1 * time.Second) 36 }