-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.go
71 lines (60 loc) · 1.38 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
package utils
import (
_log "github.com/rl404/fairy/log"
"github.com/rl404/fairy/log/chain"
"github.com/rl404/fairy/log/nop"
"github.com/rl404/fairy/log/zerolog"
)
// LogLevel is level of log that will be printed.
// Will print level that is higher than your
// chosen one.
type LogLevel int8
// Available log level.
const (
TraceLevel LogLevel = iota - 1
DebugLevel
InfoLevel
WarnLevel
ErrorLevel
FatalLevel
PanicLevel
Disabled
)
var l _log.Logger = zerolog.New(zerolog.LogLevel(TraceLevel), false, true)
var ls []_log.Logger = []_log.Logger{l}
// InitLog to init global logger.
func InitLog(lvl LogLevel, json, color bool) {
l = zerolog.New(zerolog.LogLevel(lvl), json, color)
ls = []_log.Logger{l}
}
// AddLog to add logger chain.
func AddLog(l1 _log.Logger) {
l = chain.New(l, l1)
ls = append(ls, l1)
}
// GetLogger to get logger.
func GetLogger(i ...int) _log.Logger {
if len(i) > 0 {
if len(ls) <= i[0] {
return nop.New()
}
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...)
}