github.com/zooyer/miskit@v1.0.71/log/format_test.go (about) 1 package log 2 3 import ( 4 "encoding/json" 5 "fmt" 6 "testing" 7 "time" 8 ) 9 10 func TestFormat(t *testing.T) { 11 var record = new(Record) 12 record.Time = time.Now() 13 record.Level = "DEBUG" 14 record.Tag = []Tag{ 15 {"module", "apollo"}, 16 {"trace", "10001241235"}, 17 {"type", "rpc"}, 18 {"rpc", "http"}, 19 {"latency", "10"}, 20 {"other", json.RawMessage(`{"json":"value", " ": " "}`)}, 21 } 22 record.Message = "hello world" 23 24 t.Log(JSONFormatter(false)(record)) 25 t.Log(TextFormatter(false)(record)) 26 t.Log(TextFormatter(true)(record)) 27 record.Level = "INFO" 28 t.Log(TextFormatter(true)(record)) 29 record.Level = "WARNING" 30 t.Log(TextFormatter(true)(record)) 31 record.Level = "ERROR" 32 t.Log(TextFormatter(true)(record)) 33 } 34 35 func TestFormatText(t *testing.T) { 36 for i := 0; i < 100; i++ { 37 fmt.Println(TextFormatter(true)(&Record{ 38 Level: "DEBUG", 39 Time: time.Now(), 40 Message: "null", 41 Tag: []Tag{ 42 {Key: "1", Value: ""}, 43 {Key: "2", Value: ""}, 44 {Key: "3", Value: ""}, 45 {Key: "4", Value: ""}, 46 {Key: "5", Value: ""}, 47 {Key: "6", Value: ""}, 48 {Key: "7", Value: ""}, 49 {Key: "8", Value: ""}, 50 }, 51 })) 52 } 53 }