-
-
Notifications
You must be signed in to change notification settings - Fork 89
/
logger_test.go
43 lines (36 loc) · 1.01 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
package ecspresso_test
import (
"bytes"
"testing"
"github.com/kayac/ecspresso/v2"
)
var logLevels = []string{"DEBUG", "INFO", "WARNING", "ERROR"}
func TestCommonLogger(t *testing.T) {
for _, level := range logLevels {
b := new(bytes.Buffer)
logger := ecspresso.NewLogger()
logger.SetOutput(ecspresso.NewLogFilter(b, level))
ecspresso.SetLogger(logger)
ecspresso.Log("test %s", level)
ecspresso.Log("[DEBUG] test %s", level)
ecspresso.Log("[INFO] test %s", level)
ecspresso.Log("[WARNING] test %s", level)
ecspresso.Log("[ERROR] test %s", level)
t.Log(b.String())
}
}
func TestLogger(t *testing.T) {
app := &ecspresso.App{}
for _, level := range logLevels {
b := new(bytes.Buffer)
logger := ecspresso.NewLogger()
logger.SetOutput(ecspresso.NewLogFilter(b, level))
app.SetLogger(logger)
app.Log("test %s", "test")
app.Log("[DEBUG] test %s", "test")
app.Log("[INFO] test %s", "test")
app.Log("[WARNING] test %s", "test")
app.Log("[ERROR] test %s", "test")
t.Log(b.String())
}
}