forked from twmb/franz-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathklogrus_test.go
44 lines (31 loc) · 974 Bytes
/
klogrus_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
package klogrus_test
import (
"testing"
"github.com/sirupsen/logrus"
"github.com/sirupsen/logrus/hooks/test"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/twmb/franz-go/pkg/kgo"
"github.com/twmb/franz-go/plugin/klogrus"
)
func ExampleNew() {
l := klogrus.New(logrus.New())
l.Log(kgo.LogLevelInfo, "test message", "test-key", "test-val")
// Output:
}
func TestFieldLogger(t *testing.T) {
logger, hook := test.NewNullLogger()
l := klogrus.NewFieldLogger(logger)
level := l.Level()
assert.Equal(t, kgo.LogLevelInfo, level)
l.Log(kgo.LogLevelInfo, "test message", "test-key", "test-val")
require.Equal(t, 1, len(hook.Entries))
lastEntry := hook.LastEntry()
assert.Equal(t, logrus.InfoLevel, lastEntry.Level)
assert.Equal(t, "test message", lastEntry.Message)
value, ok := lastEntry.Data["test-key"]
assert.True(t, ok)
assert.Equal(t, "test-val", value)
hook.Reset()
assert.Nil(t, hook.LastEntry())
}