-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlog.go
62 lines (49 loc) · 1.4 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
package sked
import (
"fmt"
"log"
"os"
)
// 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{})
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{}) {}
// 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
}
// NewLogLogger will create a new default logger.
func NewLogLogger() *LogLogger {
logger := log.New(os.Stderr, "sked: ", log.Lshortfile)
return &LogLogger{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...))
}
// 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...))
}