-
Notifications
You must be signed in to change notification settings - Fork 1
/
parse_test.go
63 lines (56 loc) · 1.18 KB
/
parse_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package log
import (
"testing"
"time"
)
func TestParseText(t *testing.T) {
var str = `2019-10-27 00:04:36.028 DEBUG "trace"="10001241235" "type"="rpc" "rpc"="http" "hello world"
`
r, err := ParseText(str)
if err != nil {
t.Fatal(err)
}
t.Log(FormatJson(r))
r = new(Record)
str = FormatText(r)
if r, err = ParseText(str); err != nil {
t.Fatal(err)
}
t.Log(str)
}
func TestParseColorText(t *testing.T) {
var r = new(Record)
r.Time = time.Now()
r.Level = "ERROR"
r.Message = "hello"
r.Tag = Tag{"key": "val"}
str := FormatColorText(r)
t.Log(str)
record, err := ParseColorText(str)
if err != nil {
t.Fatal(err)
}
t.Log(FormatJson(record))
r = new(Record)
str = FormatColorText(r)
t.Log(str)
record, err = ParseColorText(str)
if err != nil {
t.Fatal(err)
}
t.Log(FormatJson(record))
}
func TestParseJson(t *testing.T) {
var str = `{"level":"ERROR","message":"hello","tag":{"key":"val"},"time":"2019-10-27 22:39:08.898"}`
r, err := ParseJson(str)
if err != nil {
t.Fatal(err)
}
t.Log(FormatColorText(r))
str = `{"level":"","message":"","time":"0001-01-01 00:00:00.000"}`
r, err = ParseJson(str)
if err != nil {
t.Fatal(err)
}
t.Log(FormatColorText(r))
}