package l import ( "fmt" "testing" ) func TestLog(t *testing.T) { EnableDebug() Debug("Debug", "log") Debugf("Debugf %s", "log") Debugj("Debugj", map[string]interface{}{"name": "zhangsan", "age": 10}) Debugs("Debugs") Info("Info", "log") Infof("Infof %s", "log") Warn("Warn", "log") Warnf("Warnf %s", "log") // 正常err测试 Error() Errorf() WrapError() WrapErrorf() fmt.Println(GetError()) fmt.Println(GetErrorf()) Error("Error", "log") Errorf("Errorf %s", "log") fmt.Println(GetError("Error", "log")) fmt.Println(GetErrorf("Errorf %s", "log")) err0 := WrapError("Error", "log") fmt.Println(err0) err1 := WrapErrorf("Errorf %s", "log") fmt.Println(err1) // 测试只传入code Error(BackendModNotRunning) Errorf(BackendModNotRunning) fmt.Println(GetError(BackendModNotRunning)) fmt.Println(GetErrorf(BackendModNotRunning)) err2 := WrapError(BackendModNotRunning) fmt.Println(err2) err3 := WrapErrorf(BackendModNotRunning) fmt.Println(err3) // 测试只传入code及一个参数 Error(BackendModNotRunning, "test one code one error") Errorf(BackendModNotRunning, "test one code one error") Errorf(BackendModNotRunning, "error %s", "log") fmt.Println(GetError(BackendModNotRunning, "test one code one error")) fmt.Println(GetErrorf(BackendModNotRunning, "test one code one error")) fmt.Println(GetErrorf(BackendModNotRunning, "error %s", "log")) err4 := WrapError(BackendModNotRunning, "test one code one error") fmt.Println(err4) err5 := WrapErrorf(BackendModNotRunning, "test one code one error") fmt.Println(err5) err6 := WrapErrorf(BackendModNotRunning, "error %s", "log") fmt.Println(err6) // 测试获取errcode Error(err4) Errorf(err4) fmt.Println(GetError(err4)) fmt.Println(GetErrorf(err4)) err7 := WrapError(err4) fmt.Println(err7) err8 := WrapErrorf(err4) fmt.Println(err8) // Fatal("Fatal", "log") // Fatalf("Fatalf %s", "log") } func TestStdoutBytesAndStdoutLimit(t *testing.T) { t.Logf("before write bytes: %d", GetStdoutBytes()) SetStdoutLimit(10) t.Logf("stdout limit: %d", GetStdoutLimit()) Info("hello") Info("not print") t.Logf("after write bytes: %d", GetStdoutBytes()) }