/
logger_cus.go
49 lines (42 loc) · 1.44 KB
/
logger_cus.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
package glogs
import (
"go.uber.org/zap"
"net/http"
)
type CusLog struct {
Logger *zap.Logger
Config *Config
}
// NewLogger 得到一个zap.Logger
func NewLogger(options ...LogOptionFunc) *CusLog {
var cus = &CusLog{Config: DefaultConfig}
for _, f := range options {
f(cus.Config)
}
cus.Logger = initSugar(cus.Config)
return cus
}
func (l *CusLog) Info(template string, args ...interface{}) {
msg, fields := dealWithArgs(template, args...)
writer(nil, l.Logger, LevelInfo, msg, LevelInfo, fields...)
}
func (l *CusLog) InfoF(r *http.Request, title string, template string, args ...interface{}) {
msg, fields := dealWithArgs(template, args...)
writer(r, l.Logger, LevelInfo, msg, title, fields...)
}
func (l *CusLog) Warn(template string, args ...interface{}) {
msg, fields := dealWithArgs(template, args...)
writer(nil, l.Logger, LevelWarn, msg, LevelWarn, fields...)
}
func (l *CusLog) WarnF(r *http.Request, title string, template string, args ...interface{}) {
msg, fields := dealWithArgs(template, args...)
writer(r, l.Logger, LevelWarn, msg, title, fields...)
}
func (l *CusLog) Error(template string, args ...interface{}) {
msg, fields := dealWithArgs(template, args...)
writer(nil, l.Logger, LevelError, msg, LevelError, fields...)
}
func (l *CusLog) ErrorF(r *http.Request, title string, template string, args ...interface{}) {
msg, fields := dealWithArgs(template, args...)
writer(r, l.Logger, LevelError, msg, title, fields...)
}