-
Notifications
You must be signed in to change notification settings - Fork 3
/
log.go
50 lines (43 loc) · 1.28 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
package sched
import (
"go.uber.org/zap"
)
// Logger Sched logging interface similar to uber-go/zap, while keeping the option to change the logging implementation
// It is a sub-interface of uber-go/zap SugaredLogger.
type Logger interface {
Debugw(msg string, keysAndValues ...interface{})
Errorw(msg string, keysAndValues ...interface{})
Fatalw(msg string, keysAndValues ...interface{})
Infow(msg string, keysAndValues ...interface{})
Panicw(msg string, keysAndValues ...interface{})
Warnw(msg string, keysAndValues ...interface{})
With(args ...interface{}) Logger
Named(name string) Logger
Sync() error
}
type logger struct {
*zap.SugaredLogger
}
func (l logger) With(args ...interface{}) Logger {
return logger{SugaredLogger: l.SugaredLogger.With(args...)}
}
func (l logger) Named(name string) Logger {
return logger{SugaredLogger: l.SugaredLogger.Named(name)}
}
//DefaultLogger Return Default Sched Logger based on Zap's sugared logger
func DefaultLogger() Logger {
// TODO control verbosity
loggerBase, _ := zap.NewDevelopment()
sugarLogger := loggerBase.Sugar()
return &logger{
sugarLogger,
}
}
//NopLogger Return a No Op Logger that prints nothing.
func NopLogger() Logger {
loggerBase := zap.NewNop()
sugarLogger := loggerBase.Sugar()
return &logger{
sugarLogger,
}
}