-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.go
59 lines (52 loc) · 1.17 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
package goll
import (
"fmt"
"log"
)
// Logger interface is provided
// to allow you to customize the logging internally done
// by the limiters.
//
// The default implementation logs to the "log" standard module
// via log.Default().
//
// If you want to disable the default logger
// you can pass an instance of goll.NewNoOpLogger()
// to the limiter constructor.
type Logger interface {
Debug(string)
Info(string)
Warning(string)
Error(string)
}
type defaultLogger struct {
}
func (l *defaultLogger) Debug(text string) {
log.Default().Println(fmt.Sprintf("[debug] %v", text))
}
func (l *defaultLogger) Info(text string) {
log.Default().Println(fmt.Sprintf("[info] %v", text))
}
func (l *defaultLogger) Warning(text string) {
log.Default().Println(fmt.Sprintf("[WARNING] %v", text))
}
func (l *defaultLogger) Error(text string) {
log.Default().Println(fmt.Sprintf("[ERROR] %v", text))
}
func NewNoOpLogger() Logger {
return &noOpLogger{}
}
type noOpLogger struct {
}
func (l *noOpLogger) Debug(text string) {
// NOP
}
func (l *noOpLogger) Info(text string) {
// NOP
}
func (l *noOpLogger) Warning(text string) {
// NOP
}
func (l *noOpLogger) Error(text string) {
// NOP
}