forked from keygen-sh/keygen-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.go
68 lines (52 loc) · 1.37 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
63
64
65
66
67
68
package keygen
import (
"fmt"
"os"
)
type LogLevel uint32
const (
LogLevelNone LogLevel = iota
LogLevelError
LogLevelWarn
LogLevelInfo
LogLevelDebug
)
type logger struct {
Level LogLevel
}
func (l *logger) Errorf(format string, v ...interface{}) {
if l.Level < LogLevelError {
return
}
fmt.Fprintf(os.Stderr, "[ERROR] "+format+"\n", v...)
}
func (l *logger) Warnf(format string, v ...interface{}) {
if l.Level < LogLevelWarn {
return
}
fmt.Fprintf(os.Stderr, "[WARN] "+format+"\n", v...)
}
func (l *logger) Infof(format string, v ...interface{}) {
if l.Level < LogLevelInfo {
return
}
fmt.Fprintf(os.Stdout, "[INFO] "+format+"\n", v...)
}
func (l *logger) Debugf(format string, v ...interface{}) {
if l.Level < LogLevelDebug {
return
}
fmt.Fprintf(os.Stdout, "[DEBUG] "+format+"\n", v...)
}
// LeveledLogger provides a basic leveled logging interface for
// printing debug, informational, warning, and error messages.
type LeveledLogger interface {
// Debugf logs a debug message using Printf conventions.
Debugf(format string, v ...interface{})
// Errorf logs a warning message using Printf conventions.
Errorf(format string, v ...interface{})
// Infof logs an informational message using Printf conventions.
Infof(format string, v ...interface{})
// Warnf logs a warning message using Printf conventions.
Warnf(format string, v ...interface{})
}