generated from logur/adapter-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger_test.go
53 lines (41 loc) · 1.05 KB
/
logger_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
package kit
import (
"bytes"
"encoding/json"
"strings"
"testing"
"github.com/go-kit/kit/log"
"logur.dev/logur"
"logur.dev/logur/conformance"
)
func TestLogger(t *testing.T) {
suite := conformance.TestSuite{
NoTraceLevel: true,
LoggerFactory: func(level logur.Level) (logur.Logger, conformance.TestLogger) {
var buf bytes.Buffer
logger := log.NewJSONLogger(&buf)
return New(logger), conformance.TestLoggerFunc(func() []logur.LogEvent {
lines := strings.Split(strings.TrimSuffix(buf.String(), "\n"), "\n")
events := make([]logur.LogEvent, len(lines))
for key, line := range lines {
var event map[string]interface{}
err := json.Unmarshal([]byte(line), &event)
if err != nil {
panic(err)
}
level, _ := logur.ParseLevel(strings.ToLower(event["level"].(string)))
msg := event["msg"].(string)
delete(event, "level")
delete(event, "msg")
events[key] = logur.LogEvent{
Line: msg,
Level: level,
Fields: event,
}
}
return events
})
},
}
suite.Run(t)
}