-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloggerx.go
55 lines (46 loc) · 1.06 KB
/
loggerx.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
package zapsetup
import (
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
type LoggerX struct {
*zap.Logger
level zap.AtomicLevel
logf *zap.SugaredLogger
}
func newLoggerX(cfg *zap.Config) *LoggerX {
log, err := cfg.Build()
if err != nil {
panic(err)
}
return &LoggerX{
Logger: log,
level: cfg.Level,
logf: log.Sugar(),
}
}
// SetLevel atomically
func (l *LoggerX) SetLevel(level zapcore.Level) *LoggerX {
l.level.SetLevel(level)
return l
}
func (l *LoggerX) WithSink(s Sink, logLevel ...zapcore.Level) *LoggerX {
core := NewCoreX(l.Logger, s)
if len(logLevel) > 0 {
core.SetLogLevelForSink(logLevel[0])
}
l.Logger = zap.New(core, zap.WithCaller(true))
return l
}
func (l *LoggerX) Debugf(format string, args ...interface{}) {
l.logf.Debugf(format, args...)
}
func (l *LoggerX) Infof(format string, args ...interface{}) {
l.logf.Infof(format, args...)
}
func (l *LoggerX) Warnf(format string, args ...interface{}) {
l.logf.Warnf(format, args...)
}
func (l *LoggerX) Errorf(format string, args ...interface{}) {
l.logf.Errorf(format, args...)
}