-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.go
147 lines (113 loc) · 2.94 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package logger
import (
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
var Singleton *zap.SugaredLogger
var PlainSingleton *zap.Logger
var level zapcore.Level
var internal *zap.SugaredLogger
func Instantiate(logLevel string, disableStacktrace bool) {
if Singleton != nil || PlainSingleton != nil {
panic("logger has been instantiated")
}
err := level.Set(logLevel)
if err != nil {
panic(err.Error())
}
var conf zap.Config
if level == zapcore.DebugLevel {
conf = zap.NewDevelopmentConfig()
} else {
conf = zap.NewProductionConfig()
}
conf.Level.SetLevel(level)
conf.DisableStacktrace = disableStacktrace
PlainSingleton, err = conf.Build()
if err != nil {
panic(err.Error())
}
Singleton = PlainSingleton.Sugar()
internal = PlainSingleton.WithOptions(zap.AddCallerSkip(1)).Sugar()
}
func Level() zapcore.Level {
return level
}
type SugaredLogger struct {
*zap.SugaredLogger
}
func Named(name string) *SugaredLogger {
return &SugaredLogger{Singleton.Named(name)}
}
func (l *SugaredLogger) Event(event string) *zap.SugaredLogger {
return l.With("event", event)
}
func (l *SugaredLogger) Context(context string) *zap.SugaredLogger {
return l.With("context", context)
}
func Debug(args ...interface{}) {
internal.Debug(args...)
}
func Info(args ...interface{}) {
internal.Info(args...)
}
func Warn(args ...interface{}) {
internal.Warn(args...)
}
func Error(args ...interface{}) {
internal.Error(args...)
}
func DPanic(args ...interface{}) {
internal.DPanic(args...)
}
func Panic(args ...interface{}) {
internal.Panic(args...)
}
func Fatal(args ...interface{}) {
internal.Fatal(args...)
}
func Debugf(template string, args ...interface{}) {
internal.Debugf(template, args...)
}
func Infof(template string, args ...interface{}) {
internal.Infof(template, args...)
}
func Warnf(template string, args ...interface{}) {
internal.Warnf(template, args...)
}
func Errorf(template string, args ...interface{}) {
internal.Errorf(template, args...)
}
func DPanicf(template string, args ...interface{}) {
internal.DPanicf(template, args...)
}
func Panicf(template string, args ...interface{}) {
internal.Panicf(template, args...)
}
func Fatalf(template string, args ...interface{}) {
internal.Fatalf(template, args...)
}
func Debugw(msg string, keysAndValues ...interface{}) {
internal.Debugw(msg, keysAndValues...)
}
func Infow(msg string, keysAndValues ...interface{}) {
internal.Infow(msg, keysAndValues...)
}
func Warnw(msg string, keysAndValues ...interface{}) {
internal.Warnw(msg, keysAndValues...)
}
func Errorw(msg string, keysAndValues ...interface{}) {
internal.Errorw(msg, keysAndValues...)
}
func DPanicw(msg string, keysAndValues ...interface{}) {
internal.DPanicw(msg, keysAndValues...)
}
func Panicw(msg string, keysAndValues ...interface{}) {
internal.Panicw(msg, keysAndValues...)
}
func Fatalw(msg string, keysAndValues ...interface{}) {
internal.Fatalw(msg, keysAndValues...)
}
func Sync() error {
return internal.Sync()
}