-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.go
40 lines (32 loc) · 1008 Bytes
/
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
package rate
import "fmt"
type Logger interface {
Infof(format string, args ...any)
Debugf(format string, args ...any)
Errorf(format string, args ...any)
}
// discardLogger is [Logger] implementation that does nothing with its input.
type discardLogger struct{}
func (discardLogger) Infof(string, ...any) {}
func (discardLogger) Debugf(string, ...any) {}
func (discardLogger) Errorf(string, ...any) {}
// fmtLogger is a [Logger] implementation that prints to [os.Stdout] using a
// custom formatting template, passed to [fmt.Printf].
type fmtLogger struct{}
func (fmtLogger) Infof(format string, args ...any) {
fmt.Printf("[INFO] "+format+"\n", args...)
}
func (fmtLogger) Debugf(format string, args ...any) {
fmt.Printf("[DEBUG] "+format+"\n", args...)
}
func (fmtLogger) Errorf(format string, args ...any) {
fmt.Printf("[ERROR] "+format+"\n", args...)
}
var (
noopLogger = &discardLogger{}
standardLogger = &fmtLogger{}
)
var (
_ Logger = &discardLogger{}
_ Logger = &fmtLogger{}
)