forked from upsight/dinghy
/
log.go
82 lines (64 loc) · 2 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
package cluster
import (
"fmt"
"log"
)
// Logger is for logging to a writer. This is not the raft replication log.
type Logger interface {
Printf(format string, v ...interface{})
Println(v ...interface{})
Infof(format string, v ...interface{})
Debugf(format string, v ...interface{})
Tracef(format string, v ...interface{})
Errorf(format string, v ...interface{})
Errorln(v ...interface{})
}
// DiscardLogger is a noop logger.
type DiscardLogger struct {
}
// Println noop
func (d *DiscardLogger) Println(v ...interface{}) {}
// Printf noop
func (d *DiscardLogger) Printf(format string, v ...interface{}) {}
// Infof noop
func (d *DiscardLogger) Infof(format string, v ...interface{}) {}
// Debugf noop
func (d *DiscardLogger) Debugf(format string, v ...interface{}) {}
// Tracef noop
func (d *DiscardLogger) Tracef(format string, v ...interface{}) {}
// Errorln noop
func (d *DiscardLogger) Errorln(v ...interface{}) {}
// Errorf noop
func (d *DiscardLogger) Errorf(format string, v ...interface{}) {}
// LogLogger uses the std lib logger.
type LogLogger struct {
Logger *log.Logger
}
// Println std lib
func (d *LogLogger) Println(v ...interface{}) {
d.Logger.Output(3, "[INFO] "+fmt.Sprintln(v...))
}
// Printf std lib
func (d *LogLogger) Printf(format string, v ...interface{}) {
d.Logger.Output(3, fmt.Sprintf("[INFO] "+format, v...))
}
// Infof std lib
func (d *LogLogger) Infof(format string, v ...interface{}) {
d.Logger.Output(3, fmt.Sprintf("[INFO] "+format, v...))
}
// Debugf std lib
func (d *LogLogger) Debugf(format string, v ...interface{}) {
d.Logger.Output(3, fmt.Sprintf("[DEBU] "+format, v...))
}
// Debugf std lib
func (d *LogLogger) Tracef(format string, v ...interface{}) {
d.Logger.Output(3, fmt.Sprintf("[TRAC] "+format, v...))
}
// Errorln std lib
func (d *LogLogger) Errorln(v ...interface{}) {
d.Logger.Output(3, "[ERRO] "+fmt.Sprintln(v...))
}
// Errorf std lib
func (d *LogLogger) Errorf(format string, v ...interface{}) {
d.Logger.Output(3, fmt.Sprintf("[ERRO] "+format, v...))
}