forked from etcd-io/etcd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
debug.go
53 lines (42 loc) · 947 Bytes
/
debug.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
package etcd
import (
"io/ioutil"
"log"
"strings"
)
type Logger interface {
Debug(args ...interface{})
Debugf(fmt string, args ...interface{})
Warning(args ...interface{})
Warningf(fmt string, args ...interface{})
}
var logger Logger
func SetLogger(log Logger) {
logger = log
}
func GetLogger() Logger {
return logger
}
type defaultLogger struct {
log *log.Logger
}
func (p *defaultLogger) Debug(args ...interface{}) {
p.log.Println(args)
}
func (p *defaultLogger) Debugf(fmt string, args ...interface{}) {
// Append newline if necessary
if !strings.HasSuffix(fmt, "\n") {
fmt = fmt + "\n"
}
p.log.Printf(fmt, args)
}
func (p *defaultLogger) Warning(args ...interface{}) {
p.Debug(args)
}
func (p *defaultLogger) Warningf(fmt string, args ...interface{}) {
p.Debugf(fmt, args)
}
func init() {
// Default logger uses the go default log.
SetLogger(&defaultLogger{log.New(ioutil.Discard, "go-etcd", log.LstdFlags)})
}