-
Notifications
You must be signed in to change notification settings - Fork 0
/
golok.go
65 lines (53 loc) · 1.18 KB
/
golok.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
package golok
import (
"github.com/nurcahyo/golok/contract"
"github.com/nurcahyo/golok/handlers/stack"
"github.com/nurcahyo/golok/manager"
)
var (
defaultLogger contract.Loggable
logManager contract.Manager
)
func Initialize(cfg map[string]interface{}) {
logManager = manager.NewLogManager(cfg)
}
func ensureLogManager() {
if logManager != nil {
return
}
logManager = manager.NewLogManager(map[string]interface{}{
"default": "system",
"channels": map[string]interface{}{
"system": map[string]interface{}{
"level": "debug",
"driver": "syslog",
},
},
})
}
func defaultLog() contract.Loggable {
if defaultLogger == nil {
ensureLogManager()
defaultHandlerName := logManager.GetConfig("default", "syslog").(string)
defaultLogger = logManager.GetLog(defaultHandlerName)
}
return defaultLogger
}
func Debug(msg string) {
defaultLog().Debug(msg)
}
func Error(err error) {
defaultLog().Error(err)
}
func Critical(err error) {
defaultLog().Critical(err)
}
func Warning(msg string) {
defaultLog().Warning(msg)
}
func Info(msg string) {
defaultLog().Info(msg)
}
func Stack(channels []string) *stack.StackHandler {
return stack.NewHandler(channels, logManager)
}