-
Notifications
You must be signed in to change notification settings - Fork 0
/
kklogger_rollbar.go
92 lines (75 loc) · 1.61 KB
/
kklogger_rollbar.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
package kkrollbar
import (
"fmt"
"sync"
"github.com/kklab-com/goth-kklogger"
"github.com/rollbar/rollbar-go"
)
type KKLoggerRollbarHook struct {
Token string
Environment string
CodeVersion string
ServerHost string
ServerRoot string
Level kklogger.Level
once sync.Once
}
func (h *KKLoggerRollbarHook) _Init() {
h.once.Do(func() {
rollbar.SetToken(h.Token)
rollbar.SetEnvironment(h.Environment)
rollbar.SetCodeVersion(h.CodeVersion)
rollbar.SetServerHost(h.ServerHost)
rollbar.SetServerRoot(h.ServerRoot)
})
}
func (h *KKLoggerRollbarHook) LogString(args ...interface{}) string {
if args == nil {
return ""
}
args = args[0].([]interface{})
argl := len(args)
if argl == 1 {
switch tp := args[0].(type) {
case string:
return tp
}
} else if argl > 1 {
switch tp := args[0].(type) {
case string:
pargs := args[1:]
return fmt.Sprintf(tp, pargs...)
}
}
return fmt.Sprint(args...)
}
func (h *KKLoggerRollbarHook) Trace(args ...interface{}) {
}
func (h *KKLoggerRollbarHook) Debug(args ...interface{}) {
if h.Level < kklogger.DebugLevel {
return
}
h._Init()
rollbar.Debug(h.LogString(args...))
}
func (h *KKLoggerRollbarHook) Info(args ...interface{}) {
if h.Level < kklogger.InfoLevel {
return
}
h._Init()
rollbar.Info(h.LogString(args...))
}
func (h *KKLoggerRollbarHook) Warn(args ...interface{}) {
if h.Level < kklogger.WarnLevel {
return
}
h._Init()
rollbar.Warning(h.LogString(args...))
}
func (h *KKLoggerRollbarHook) Error(args ...interface{}) {
if h.Level < kklogger.ErrorLevel {
return
}
h._Init()
rollbar.Error(h.LogString(args...))
}