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