-
Notifications
You must be signed in to change notification settings - Fork 0
/
log_test.go
158 lines (123 loc) · 3.44 KB
/
log_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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package log
import (
"fmt"
"testing"
)
func TestSetupSingleLogger(t *testing.T) {
SetupLogger(LogLevelDebug, LogFormatPretty, TimeFormatLoggly, false, true, []string{"test"})
Infoln("This is an info statement.")
}
func TestSetupLocalLogger(t *testing.T) {
SetupLocalLogger(LogLevelInfo)
Infoln("This is an info statement.")
}
func TestSetupCloudLogger(t *testing.T) {
SetupCloudLogger(LogLevelInfo, []string{"test", "tags"})
Infoln("This is an info statement.")
}
func TestInfod(t *testing.T) {
SetupLocalLogger(LogLevelDebug)
type testStruct struct {
Name string
Kind string
}
test := &testStruct{
Name: "Logan",
Kind: "log",
}
Infod("This is some data.", test)
}
func TestWhitespace(t *testing.T) {
type testStruct struct {
Name string
Kind string
}
data := &testStruct{
Name: "Logan",
Kind: "log",
}
message := `
This is some data.
`
t.Run("Pretty", func(t *testing.T) {
SetupLocalLogger(LogLevelDebug)
Infod(message, data)
})
t.Run("JSON", func(t *testing.T) {
SetupCloudLogger(LogLevelDebug, []string{"logger", "test"})
Infod(message, data)
})
}
func TestTrace(t *testing.T) {
SetupLogger(LogLevelTrace, LogFormatJSON, TimeFormatLoggly, false, true, []string{"test", "tags"})
t.Run("Traceln", func(t *testing.T) {
Traceln("This is a trace ln statement.")
})
t.Run("Tracef", func(t *testing.T) {
Tracef("This is a trace f statement %d.", 10000)
})
t.Run("Traced", func(t *testing.T) {
Traced("This is a trace d statement.", 10000)
})
}
func TestDebug(t *testing.T) {
SetupLogger(LogLevelDebug, LogFormatJSON, TimeFormatLoggly, false, true, []string{"test", "tags"})
t.Run("Debugln", func(t *testing.T) {
Debugln("This is a debug ln statement.")
})
t.Run("Debugf", func(t *testing.T) {
Debugf("This is a debug f statement %d.", 10000)
})
t.Run("Debugd", func(t *testing.T) {
Debugd("This is a debug d statement.", 10000)
})
}
func TestInfo(t *testing.T) {
SetupLogger(LogLevelDebug, LogFormatJSON, TimeFormatLoggly, false, true, []string{"test", "tags"})
t.Run("Infoln", func(t *testing.T) {
Infoln("This is an info ln statement.")
})
t.Run("Infof", func(t *testing.T) {
Infof("This is an info f statement %d.", 10000)
})
t.Run("Infod", func(t *testing.T) {
Infod("This is an info f statement.", 10000)
})
}
func TestWarn(t *testing.T) {
SetupLogger(LogLevelDebug, LogFormatJSON, TimeFormatLoggly, false, true, []string{"test", "tags"})
t.Run("Warnln", func(t *testing.T) {
Warnln("This is a warning ln.")
})
t.Run("Warnf", func(t *testing.T) {
Warnf("This is a warning f %d.", 10000)
})
t.Run("Warnd", func(t *testing.T) {
Warnd("This is a warning d.", 10000)
})
}
func TestError(t *testing.T) {
SetupLogger(LogLevelDebug, LogFormatJSON, TimeFormatLoggly, false, true, []string{"test", "tags"})
t.Run("Errorln", func(t *testing.T) {
Errorln("This is an error ln.")
})
t.Run("Errorf", func(t *testing.T) {
Errorf("This is an error f %d.", 10000)
})
t.Run("Errord", func(t *testing.T) {
Errord("This is an error d.", 10000)
})
}
func TestFatal(t *testing.T) {
SetupLogger(LogLevelDebug, LogFormatJSON, TimeFormatLoggly, false, true, []string{"test", "tags"})
LoggerSingleton.exitFunc = func() { fmt.Println("> os.Exit(1)") }
t.Run("Fatalln", func(t *testing.T) {
Fatalln("This is a fatal ln.")
})
t.Run("Fatalf", func(t *testing.T) {
Fatalf("This is a fatal f %d.", 10000)
})
t.Run("Fatald", func(t *testing.T) {
Fatald("This is a fatal d.", 10000)
})
}