-
Notifications
You must be signed in to change notification settings - Fork 1
/
log_test.go
121 lines (103 loc) · 2.77 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
// Copyright 2024 mlycore. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package log
import (
"fmt"
"os"
"runtime"
"testing"
)
func Test_Log(t *testing.T) {
NewDefaultLogger()
SetFormatter(&TextFormatter{Color: false})
logger.SetLevelByName("TRACE")
printall(logger.Level)
logger.SetLevelByName("DEBUG")
printall(logger.Level)
logger.SetLevelByName("INFO")
printall(logger.Level)
logger.SetLevelByName("WARN")
printall(logger.Level)
logger.SetLevelByName("ERROR")
printall(logger.Level)
logger.SetLevelByName("FATAL")
printall(logger.Level)
}
func printall(level int) {
l := LogLevelMap[level]
str := fmt.Sprintf("this is level %s", l)
Traceln("traceln: " + str)
Tracef("tracef: %s", str)
Debugln("debugln: " + str)
Debugf("debugf: %s", str)
Infoln("infoln: " + str)
Infof("infof: %s", str)
Warnln("warnln: " + str)
Warnf("warnf: %s", str)
Errorln("errorln: " + str)
Errorf("errorf: %s", str)
//Fatalln("fatalln: " + str)
//Fatalf("fatalf: %s", str)
}
func Test_FuncInfo(t *testing.T) {
Traceln("this is traceln")
data := make([]byte, 10240)
runtime.Stack(data, true)
fmt.Printf("%s\n", string(data))
}
func Test_GetShortFileName(t *testing.T) {
name := "github.com/xuyun-io/kubestar/pkg/controllers/crd/application.(*ApplicationController).List"
NewLogger(os.Stdout, 0, 3)
SetLevel("ERROR")
Errorf("%s", getShortFileName(name))
// t.Logf("%s\n", getShortFileName(name))
}
func Test_FormatterLogger(t *testing.T) {
NewDefaultLogger()
SetFormatter(&JSONFormatter{})
// SetFormatter(&TextFormatter{})
/*
SetContext(Context{
"namespace": "default",
"deployment": "kubestar",
})
*/
Infoln("deployment create success")
Errorf("service create error")
SetContext(Context{
"namespace": "starpay",
"deployment": "uuid",
})
Infoln("deployment list success")
}
func Test_DefaultLogger(t *testing.T) {
NewDefaultLogger()
SetFormatter(&TextFormatter{})
logger.SetLevelByName("InFo")
//printall(logger.Level)
logger.Infoln("a", "b")
}
func Benchmark_Infof(b *testing.B) {
NewDefaultLogger()
SetFormatter(&TextFormatter{})
logger.SetLevelByName("TRACE")
for i := 0; i < b.N; i++ {
logger.Infof("key %s", "value")
}
}
func Test_LogFile(t *testing.T) {
NewDefaultLogger()
SetLogFile("./test.log")
logger.Infoln("a", "b")
}