...
1 package logrus
2
3 import (
4 "bytes"
5 "encoding/json"
6 "fmt"
7 "testing"
8
9 "github.com/stretchr/testify/require"
10 )
11
12 func TestFieldValueError(t *testing.T) {
13 buf := &bytes.Buffer{}
14 l := &Logger{
15 Out: buf,
16 Formatter: new(JSONFormatter),
17 Hooks: make(LevelHooks),
18 Level: DebugLevel,
19 }
20 l.WithField("func", func() {}).Info("test")
21 fmt.Println(buf.String())
22 var data map[string]interface{}
23 json.Unmarshal(buf.Bytes(), &data)
24 _, ok := data[FieldKeyLogrusError]
25 require.True(t, ok)
26 }
27
28 func TestNoFieldValueError(t *testing.T) {
29 buf := &bytes.Buffer{}
30 l := &Logger{
31 Out: buf,
32 Formatter: new(JSONFormatter),
33 Hooks: make(LevelHooks),
34 Level: DebugLevel,
35 }
36 l.WithField("str", "str").Info("test")
37 fmt.Println(buf.String())
38 var data map[string]interface{}
39 json.Unmarshal(buf.Bytes(), &data)
40 _, ok := data[FieldKeyLogrusError]
41 require.False(t, ok)
42 }
43
View as plain text