-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogging.go
56 lines (46 loc) · 1.15 KB
/
logging.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
package iapetus
import (
"log"
"os"
)
// LogLevel represents the severity of a log message
type LogLevel int
const (
DEBUG LogLevel = iota
INFO
ERROR
)
type Logger interface {
Debug(format string, args ...interface{})
Info(format string, args ...interface{})
Error(format string, args ...interface{})
SetLevel(level LogLevel)
}
// DefaultLogger implements Logger using the standard log package
type DefaultLogger struct {
level LogLevel
logger *log.Logger
}
// NewDefaultLogger creates a new DefaultLogger with INFO as default level
func NewDefaultLogger(level *LogLevel) *DefaultLogger {
return &DefaultLogger{
level: *level,
logger: log.New(os.Stdout, "", log.LstdFlags),
}
}
func (l *DefaultLogger) Debug(format string, args ...interface{}) {
if l.level <= DEBUG {
l.logger.Printf("[DEBUG] "+format, args...)
}
}
func (l *DefaultLogger) Info(format string, args ...interface{}) {
l.logger.Printf("[INFO] "+format, args...)
}
func (l *DefaultLogger) Error(format string, args ...interface{}) {
if l.level == ERROR {
l.logger.Printf("[ERROR] "+format, args...)
}
}
func (l *DefaultLogger) SetLevel(level LogLevel) {
l.level = level
}