forked from doloopwhile/logrusltsv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformatter_test.go
61 lines (52 loc) · 1.32 KB
/
formatter_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
package logrusltsv
import (
"strings"
"testing"
"time"
"github.com/Sirupsen/logrus"
"github.com/stretchr/testify/assert"
)
type UserValue struct{}
func (*UserValue) String() string {
return ".String() was\tused\n"
}
func TestFormatter(t *testing.T) {
assert := assert.New(t)
loc, err := time.LoadLocation("Asia/Tokyo")
assert.NoError(err)
entry := &logrus.Entry{
Data: logrus.Fields{
"app": "test",
"time": "field time",
"msg": "field msg",
"level": "field level",
"custom": &UserValue{},
"field\nwith\tspecial": "value\nwith\tspecial",
},
Time: time.Date(2015, 1, 30, 16, 01, 47, 89, loc),
Message: "test\a message\n",
Level: logrus.ErrorLevel,
}
// Fields are sorted by alphabetical
// "time", "msg", "level" fields are prefiexed with "field."
// Special charactors are quoted
// Field values are converted to string with /String() if it has.
// Line ends with "\n"
f := &Formatter{}
output, err := f.Format(entry)
assert.NoError(err)
assert.Equal(
strings.Join([]string{
`time:2015-01-30T16:01:47+09:00`,
`level:error`,
`msg:test\a message\n`,
`app:test`,
`custom:.String() was\tused\n`,
`field.level:field level`,
`field.msg:field msg`,
`field.time:field time`,
`field\nwith\tspecial:value\nwith\tspecial`,
}, "\t")+"\n",
string(output),
)
}