-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.go
64 lines (51 loc) · 1.45 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
package main
import (
"fmt"
)
// Logger describes basic logging functions.
type Logger interface {
Info(...interface{})
Infof(string, ...interface{})
Error(...interface{})
Errorf(string, ...interface{})
Println(...interface{})
Printf(string, ...interface{})
}
type voidLog struct{}
func (l *voidLog) Info(...interface{}) {}
func (l *voidLog) Infof(string, ...interface{}) {}
func (l *voidLog) Error(...interface{}) {}
func (l *voidLog) Errorf(string, ...interface{}) {}
func (l *voidLog) Println(...interface{}) {}
func (l *voidLog) Printf(string, ...interface{}) {}
type replScopedLog struct {
Logger
prefix string
}
func newReplScopedLog(log Logger, prefix string, id, ct int) *replScopedLog {
if log == nil {
log = &voidLog{}
}
return &replScopedLog{
Logger: log,
prefix: fmt.Sprintf("%02d-%s-%03d: ", id, prefix, ct),
}
}
func (l *replScopedLog) Info(args ...interface{}) {
l.Logger.Info(l.prefix + fmt.Sprint(args...))
}
func (l *replScopedLog) Infof(format string, args ...interface{}) {
l.Logger.Infof(l.prefix+format, args...)
}
func (l *replScopedLog) Error(args ...interface{}) {
l.Logger.Error(l.prefix + fmt.Sprint(args...))
}
func (l *replScopedLog) Errorf(format string, args ...interface{}) {
l.Logger.Errorf(l.prefix+format, args...)
}
func (l *replScopedLog) Println(args ...interface{}) {
l.Error(args...)
}
func (l *replScopedLog) Printf(format string, args ...interface{}) {
l.Errorf(format, args...)
}