-
Notifications
You must be signed in to change notification settings - Fork 8
/
log.go
89 lines (70 loc) · 1.57 KB
/
log.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
77
78
79
80
81
82
83
84
85
86
87
88
89
package cronowriter
import (
"fmt"
"io"
"os"
)
type (
logger interface {
Write(b []byte)
Error(args ...interface{})
Errorf(format string, args ...interface{})
}
nopLogger struct{}
debugLogger struct {
stdout io.Writer
stderr io.Writer
}
stdoutLogger struct {
w io.Writer
}
stderrLogger struct {
w io.Writer
}
)
func newDebugLogger() *debugLogger {
return &debugLogger{
stdout: os.Stdout,
stderr: os.Stderr,
}
}
func newStdoutLogger() *stdoutLogger {
return &stdoutLogger{
w: os.Stdout,
}
}
func newStderrLogger() *stderrLogger {
return &stderrLogger{
w: os.Stderr,
}
}
func (l *nopLogger) Write(b []byte) {}
func (l *nopLogger) Error(args ...interface{}) {}
func (l *nopLogger) Errorf(format string, args ...interface{}) {}
func (l *debugLogger) Write(b []byte) {
fmt.Fprintf(l.stdout, "%s", b)
}
func (l *debugLogger) Error(args ...interface{}) {
fmt.Fprintln(l.stderr, args...)
}
func (l *debugLogger) Errorf(format string, args ...interface{}) {
fmt.Fprintf(l.stderr, format, args...)
}
func (l *stdoutLogger) Write(b []byte) {
fmt.Fprintf(l.w, "%s", b)
}
func (l *stdoutLogger) Error(args ...interface{}) {
fmt.Fprintln(l.w, args...)
}
func (l *stdoutLogger) Errorf(format string, args ...interface{}) {
fmt.Fprintf(l.w, format, args...)
}
func (l *stderrLogger) Write(b []byte) {
fmt.Fprintf(l.w, "%s", b)
}
func (l *stderrLogger) Error(args ...interface{}) {
fmt.Fprintln(l.w, args...)
}
func (l *stderrLogger) Errorf(format string, args ...interface{}) {
fmt.Fprintf(l.w, format, args...)
}