interview-one-stop-server/util/log/log_test.go

38 lines
705 B
Go

package log
import (
"context"
"errors"
"fmt"
"interview-one-stop-server/util"
"testing"
)
func TestLog(t *testing.T) {
ctx := context.WithValue(context.Background(), "trace_id", util.GenUUID())
err := errors.New("it's an error")
Error(ctx, "TestLog Error", fmt.Sprintf("err is %s,value is %+v", err.Error(), struct {
Name string
Age int
}{
"issue",
2,
}))
Warn(ctx, "TestLog Warn", fmt.Sprintf("err is %s,value is %v", errors.New("it's an error").Error(), struct {
Name string
Age int
}{
"issue",
2,
}))
Info(ctx, "TestLog Info", fmt.Sprintf("no error,value is %+v", struct {
Name string
Age int
}{
"issue",
2,
}))
Debug(ctx, "TestLog Debug", "it's end")
}