-
Notifications
You must be signed in to change notification settings - Fork 164
/
logger.go
76 lines (55 loc) · 1.57 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package tls_client
import "fmt"
type Logger interface {
Debug(format string, args ...any)
Info(format string, args ...any)
Warn(format string, args ...any)
Error(format string, args ...any)
}
type noopLogger struct {
}
func NewNoopLogger() Logger {
return &noopLogger{}
}
func (n noopLogger) Debug(_ string, _ ...any) {}
func (n noopLogger) Info(_ string, _ ...any) {}
func (n noopLogger) Warn(_ string, _ ...any) {}
func (n noopLogger) Error(_ string, _ ...any) {}
type debugLogger struct {
logger Logger
}
func NewDebugLogger(logger Logger) Logger {
return &debugLogger{
logger: logger,
}
}
func (n debugLogger) Debug(format string, args ...any) {
fmt.Printf(format+"\n", args...)
}
func (n debugLogger) Info(format string, args ...any) {
n.logger.Info(format, args...)
}
func (n debugLogger) Warn(format string, args ...any) {
n.logger.Warn(format, args...)
}
func (n debugLogger) Error(format string, args ...any) {
n.logger.Error(format, args...)
}
type logger struct{}
func NewLogger() Logger {
return &logger{}
}
func (n logger) Debug(_ string, _ ...any) {}
func (n logger) Info(format string, args ...any) {
fmt.Printf(format+"\n", args...)
}
func (n logger) Warn(format string, args ...any) {
fmt.Printf(format+"\n", args...)
}
func (n logger) Error(format string, args ...any) {
fmt.Printf(format+"\n", args...)
}
// Interface guards are a cheap way to make sure all methods are implemented, this is a static check and does not affect runtime performance.
var _ Logger = (*logger)(nil)
var _ Logger = (*debugLogger)(nil)
var _ Logger = (*noopLogger)(nil)