-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.go
91 lines (76 loc) · 1.46 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
89
90
91
package ssql
import (
"fmt"
)
const (
LevelError = iota + 1 // 1
LevelInfo // 2
LevelWarn // 3
LevelDebug // 4
)
type Logger interface {
Print(v ...any)
Printf(format string, v ...any)
}
type defaultLogger struct{}
func (_ defaultLogger) Print(v ...any) {
fmt.Println(v...)
}
func (_ defaultLogger) Printf(format string, v ...any) {
fmt.Printf(format+"\n", v...)
}
type log struct {
logger *Logger
level int
}
func (log *log) debug(v ...any) {
if log.level < 4 {
return
}
(*log.logger).Print(v...)
}
func (log *log) debugf(format string, v ...any) {
if log.level < 4 {
return
}
(*log.logger).Printf(format, v...)
}
func (log *log) warn(v ...any) {
if log.level < 3 {
return
}
(*log.logger).Print(v...)
}
func (log *log) warnf(format string, v ...any) {
if log.level < 3 {
return
}
(*log.logger).Printf(format, v...)
}
func (log *log) info(v ...any) {
if log.level < 2 {
return
}
(*log.logger).Print(v...)
}
func (log *log) infof(format string, v ...any) {
if log.level < 2 {
return
}
(*log.logger).Printf(format, v...)
}
func (log *log) error(err error, v ...any) {
if log.level < 1 {
return
}
v = append(v, fmt.Sprintf("error: %s", err))
(*log.logger).Print(v...)
}
func (log *log) errorf(err error, format string, v ...any) {
if log.level < 1 {
return
}
v = append(v, fmt.Sprintf("error: %s", err))
format = fmt.Sprintf("%s error: %s", format, err)
(*log.logger).Printf(format, v...)
}