-
Notifications
You must be signed in to change notification settings - Fork 26
/
log_test.go
60 lines (56 loc) · 1.46 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
package yee
import (
"github.com/cookieY/yee/logger"
"github.com/stretchr/testify/assert"
"net/http"
"net/http/httptest"
"testing"
)
func TestLogger_LogWrite(t *testing.T) {
y := New()
y.SetLogLevel(logger.Warning)
//file, err := os.OpenFile("logrus.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
//if err != nil {
// t.Log(err)
// return
//}
//y.SetLogOut(file)
y.POST("/hello/k/:b", func(c Context) error {
c.Logger().Critical("critical")
c.Logger().Error("error")
c.Logger().Warn("warn")
c.Logger().Info("info")
c.Logger().Debug("debug")
c.Logger().Criticalf("test:%v", 123)
c.Logger().Errorf("test:%v", 123)
c.Logger().Warnf("test:%v", 123)
c.Logger().Infof("test:%v", 123)
c.Logger().Debugf("test:%v", 123)
return c.String(http.StatusOK, c.Params("b"))
})
t.Run("http_get", func(t *testing.T) {
req := httptest.NewRequest(http.MethodPost, "/hello/k/henry", nil)
rec := httptest.NewRecorder()
y.ServeHTTP(rec, req)
tx := assert.New(t)
tx.Equal("henry", rec.Body.String())
//assert.Equal("*", rec.Header().Get(yee.HeaderAccessControlAllowOrigin))
})
}
func BenchmarkLogger_LogWrite(b *testing.B) {
l := logger.LogCreator()
b.ReportAllocs()
b.SetBytes(1024 * 1024)
for i := 0; i < b.N; i++ {
l.Critical("critical")
l.Error("error")
l.Warn("warn")
l.Info("info")
l.Debug("debug")
l.Criticalf("test:%v", 123)
l.Errorf("test:%v", 123)
l.Warnf("test:%v", 123)
l.Infof("test:%v", 123)
l.Debugf("test:%v", 123)
}
}