-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathlogger.go
88 lines (73 loc) · 1.61 KB
/
logger.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
package be_indexer
import "fmt"
const (
DebugLevel = iota
InfoLevel
ErrorLevel
)
var (
LogLevel int = InfoLevel // control defaultLogger log level
Logger BEIndexLogger = &DefaultLogger{}
)
type (
BEIndexLogger interface {
Debugf(format string, v ...interface{})
Infof(format string, v ...interface{})
Errorf(format string, v ...interface{})
}
// DefaultLogger a console logger use fmt lib
DefaultLogger struct {
}
)
func LogDebugIf(condition bool, format string, v ...interface{}) {
if condition {
Logger.Debugf(format, v...)
}
}
func LogInfoIf(condition bool, format string, v ...interface{}) {
if condition {
Logger.Infof(format, v...)
}
}
func LogErrIf(condition bool, format string, v ...interface{}) {
if condition {
Logger.Errorf(format, v...)
}
}
func LogIfErr(err error, format string, v ...interface{}) {
if err == nil {
return
}
Logger.Errorf(format, v...)
Logger.Errorf("Error:%s", err.Error())
}
func LogErr(format string, v ...interface{}) {
Logger.Errorf(format, v...)
}
func LogInfo(format string, v ...interface{}) {
Logger.Infof(format, v...)
}
func LogDebug(format string, v ...interface{}) {
Logger.Debugf(format, v...)
}
func (l *DefaultLogger) Debugf(format string, v ...interface{}) {
if LogLevel > DebugLevel {
return
}
fmt.Printf(format, v...)
fmt.Println()
}
func (l *DefaultLogger) Infof(format string, v ...interface{}) {
if LogLevel > InfoLevel {
return
}
fmt.Printf(format, v...)
fmt.Println()
}
func (l *DefaultLogger) Errorf(format string, v ...interface{}) {
if LogLevel > ErrorLevel {
return
}
fmt.Printf(format, v...)
fmt.Println()
}