-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathlog.go
62 lines (53 loc) · 1.34 KB
/
log.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
package veldt
const (
// Error indicates error-level logging
Error LogLevel = 4
// Warn indicates warn-level logging
Warn LogLevel = 3
// Info indicates info-level logging
Info LogLevel = 2
// Debug indicated debug-level logging
Debug LogLevel = 1
)
var (
logger Logger
level LogLevel
)
// LogLevel represents a logging level.
type LogLevel int
// Logger represents a logger interface for tracing internal operations.
type Logger interface {
Debugf(format string, v ...interface{})
Infof(format string, v ...interface{})
Warnf(format string, v ...interface{})
Errorf(format string, v ...interface{})
}
// SetLogger sets the logger and logging level.
func SetLogger(lvl LogLevel, log Logger) {
logger = log
level = lvl
}
// Debugf logs to the debug log.
func Debugf(format string, args ...interface{}) {
if logger != nil && level <= Debug {
logger.Debugf(format, args...)
}
}
// Infof logs to the info log.
func Infof(format string, args ...interface{}) {
if logger != nil && level <= Info {
logger.Infof(format, args...)
}
}
// Warnf logs to the warn log.
func Warnf(format string, args ...interface{}) {
if logger != nil && level <= Warn {
logger.Warnf(format, args...)
}
}
// Errorf logs to the err log.
func Errorf(format string, args ...interface{}) {
if logger != nil && level <= Error {
logger.Errorf(format, args...)
}
}