-
Notifications
You must be signed in to change notification settings - Fork 8
/
test.go
57 lines (46 loc) · 1.55 KB
/
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
package main
import (
"errors"
"fmt"
cblog "github.com/cloud-barista/cb-log"
"github.com/sirupsen/logrus"
)
var cblogger *logrus.Logger
func init() {
// cblog is a global variable.
cblogger = cblog.GetLogger("CB-SPIDER")
cblog.SetLevel("error")
cblog.SetLevel("warn")
cblog.SetLevel("info")
}
func main() {
fmt.Printf("\n####LogLevel: %s\n", cblog.GetLevel())
cblogger.Info("Log Info message")
cblogger.Warning("Log Waring message")
cblogger.Error("Log Error message")
cblogger.Errorf("Log Error message:%s", errorMsg())
cblog.SetLevel("warn")
fmt.Printf("\n####LogLevel: %s\n", cblog.GetLevel())
cblogger.Info("Log Info message")
cblogger.Warning("Log Waring message")
cblogger.Error("Log Error message")
cblogger.Errorf("Log Error message:%s", errorMsg())
cblog.SetLevel("error")
fmt.Printf("\n####LogLevel: %s\n", cblog.GetLevel())
cblogger.Info("Log Info message")
cblogger.Warning("Log Waring message")
cblogger.Error("Log Error message")
cblogger.Errorf("Log Error message:%s", errorMsg())
cblog.SetLevel("debug")
fmt.Printf("\n####LogLevel: %s\n", cblog.GetLevel())
// WithField 테스트
cblogger.WithField("TestField", "test").Debug("WithField 테스트")
// WithFields 테스트
cblogger.WithFields(logrus.Fields{"Field1": "value1", "Field2": "value2", "Field3": "value3"}).Debug("WithFields 테스트")
// WithError 테스트
cblogger.WithError(errors.New("테스트 오류")).Debug("WithError 테스트")
// fmt.Printf("===> %#v\n", cblogger.Hooks[0][0])
}
func errorMsg() error {
return fmt.Errorf("internal error message")
}