-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.go
73 lines (63 loc) · 1.33 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
package utils
import (
"github.com/rl404/fairy/log"
)
var l log.Logger
var ls []log.Logger
func init() {
l, _ = log.New(log.Config{
Type: log.Zerolog,
Level: log.TraceLevel,
JsonFormat: false,
Color: true,
})
ls = []log.Logger{l}
}
// InitLog to init global logger.
func InitLog(t log.LogType, lvl log.LogLevel, json, color bool) (err error) {
l, err = log.New(log.Config{
Type: t,
Level: lvl,
JsonFormat: json,
Color: color,
})
if err != nil {
return err
}
ls = []log.Logger{l}
return nil
}
// AddLog to add logger chain.
func AddLog(l1 log.Logger, l2 ...log.Logger) {
l = log.NewChain(l, l1)
l = log.NewChain(l, l2...)
ls = append(ls, l1)
ls = append(ls, l2...)
}
// GetLogger to get logger.
func GetLogger(i ...int) log.Logger {
if len(i) > 0 {
if len(ls) <= i[0] {
tmp, _ := log.New(log.Config{Type: log.NoLog})
return tmp
}
return ls[i[0]]
}
return l
}
// Log to log with custom field.
func Log(field map[string]interface{}) {
GetLogger().Log(field)
}
// Info to log info.
func Info(str string, args ...interface{}) {
GetLogger().Info(str, args...)
}
// Error to print error.
func Error(str string, args ...interface{}) {
GetLogger().Error(str, args...)
}
// Fatal to log fatal.
func Fatal(str string, args ...interface{}) {
GetLogger().Fatal(str, args...)
}