This repository has been archived by the owner on Jan 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
log.go
94 lines (74 loc) · 2.08 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
package hikaru
const (
LogNo = iota
LogCritical
LogError
LogWarn
LogInfo
LogDebug
LogTrace
)
var (
applicationLogger Logger
generalLogger Logger
)
type Logger interface {
V(int) bool
Printf(c *Context, level int, format string, args ...interface{})
}
func init() {
SetLogger(NewLogger(LogInfo))
SetGeneralLogger(NewLogger(LogWarn))
}
func SetLogger(logger Logger) {
applicationLogger = logger
}
func SetGeneralLogger(logger Logger) {
generalLogger = logger
}
func logGenf(c *Context, level int, format string, args ...interface{}) {
if generalLogger != nil && generalLogger.V(level) {
generalLogger.Printf(c, level, format, args...)
}
}
func logAppf(c *Context, level int, format string, args ...interface{}) {
if applicationLogger != nil && applicationLogger.V(level) {
applicationLogger.Printf(c, level, format, args...)
}
}
func (c *Context) tracef(format string, args ...interface{}) {
logGenf(c, LogTrace, format, args...)
}
func (c *Context) debugf(format string, args ...interface{}) {
logGenf(c, LogDebug, format, args...)
}
func (c *Context) infof(format string, args ...interface{}) {
logGenf(c, LogInfo, format, args...)
}
func (c *Context) warningf(format string, args ...interface{}) {
logGenf(c, LogWarn, format, args...)
}
func (c *Context) errorf(format string, args ...interface{}) {
logGenf(c, LogError, format, args...)
}
func (c *Context) criticalf(format string, args ...interface{}) {
logGenf(c, LogCritical, format, args...)
}
func (c *Context) Tracef(format string, args ...interface{}) {
logAppf(c, LogTrace, format, args...)
}
func (c *Context) Debugf(format string, args ...interface{}) {
logAppf(c, LogDebug, format, args...)
}
func (c *Context) Infof(format string, args ...interface{}) {
logAppf(c, LogInfo, format, args...)
}
func (c *Context) Warningf(format string, args ...interface{}) {
logAppf(c, LogWarn, format, args...)
}
func (c *Context) Errorf(format string, args ...interface{}) {
logAppf(c, LogError, format, args...)
}
func (c *Context) Criticalf(format string, args ...interface{}) {
logAppf(c, LogCritical, format, args...)
}