-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger.go
More file actions
97 lines (73 loc) · 1.92 KB
/
logger.go
File metadata and controls
97 lines (73 loc) · 1.92 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package auth0cliauthorizer
import (
"fmt"
"strings"
)
type Logger interface {
Debug(args ...interface{})
Info(args ...interface{})
Warning(args ...interface{})
Error(args ...interface{})
}
type consoleLogger struct{}
var _ Logger = &consoleLogger{}
func (c consoleLogger) Debug(args ...interface{}) {
fmt.Println("[debug] " + c.message(args))
}
func (c consoleLogger) Info(args ...interface{}) {
fmt.Println("[info] " + c.message(args))
}
func (c consoleLogger) Warning(args ...interface{}) {
fmt.Println("[WARN] " + c.message(args))
}
func (c consoleLogger) Error(args ...interface{}) {
fmt.Println("[ERROR] " + c.message(args))
}
func (c consoleLogger) message(args ...interface{}) string {
msg := ""
for _, a := range args {
msg += fmt.Sprintf("%v ", a)
}
return strings.TrimSuffix(msg, " ")
}
type noOpLogger struct{}
var _ Logger = &noOpLogger{}
func (c noOpLogger) Debug(_ ...interface{}) {
// NOP
}
func (c noOpLogger) Info(_ ...interface{}) {
// NOP
}
func (c noOpLogger) Warning(_ ...interface{}) {
// NOP
}
func (c noOpLogger) Error(_ ...interface{}) {
// NOP
}
type loggerWrapper struct {
underlying Logger
}
func (a *loggerWrapper) Debug(args ...interface{}) {
a.underlying.Debug(args...)
}
func (a *loggerWrapper) Info(args ...interface{}) {
a.underlying.Info(args...)
}
func (a *loggerWrapper) Warning(args ...interface{}) {
a.underlying.Warning(args...)
}
func (a *loggerWrapper) Error(args ...interface{}) {
a.underlying.Error(args...)
}
func (a *loggerWrapper) Debugf(msg string, args ...interface{}) {
a.underlying.Debug(fmt.Sprintf(msg, args...))
}
func (a *loggerWrapper) Infof(msg string, args ...interface{}) {
a.underlying.Info(fmt.Sprintf(msg, args...))
}
func (a *loggerWrapper) Warningf(msg string, args ...interface{}) {
a.underlying.Warning(fmt.Sprintf(msg, args...))
}
func (a *loggerWrapper) Errorf(msg string, args ...interface{}) {
a.underlying.Error(fmt.Sprintf(msg, args...))
}