-
Notifications
You must be signed in to change notification settings - Fork 1
/
base.go
70 lines (55 loc) · 1.34 KB
/
base.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
package svc
import (
"github.com/goinbox/golog"
"github.com/goinbox/gomisc"
)
type BaseSvc struct {
accessLogger golog.ILogger
}
func NewBaseSvc() *BaseSvc {
return &BaseSvc{
accessLogger: new(golog.NoopLogger),
}
}
func (b *BaseSvc) SetAccessLogger(logger golog.ILogger) *BaseSvc {
if logger != nil {
b.accessLogger = logger
}
return b
}
func (b *BaseSvc) AccessLogger() golog.ILogger {
return b.accessLogger
}
func (b *BaseSvc) DebugLog(kind, msg []byte) {
b.accessLogger.Debug(b.makeLogMsg(kind, msg))
}
func (b *BaseSvc) InfoLog(kind, msg []byte) {
b.accessLogger.Info(b.makeLogMsg(kind, msg))
}
func (b *BaseSvc) NoticeLog(kind, msg []byte) {
b.accessLogger.Notice(b.makeLogMsg(kind, msg))
}
func (b *BaseSvc) WarningLog(kind, msg []byte) {
b.accessLogger.Warning(b.makeLogMsg(kind, msg))
}
func (b *BaseSvc) ErrorLog(kind, msg []byte) {
b.accessLogger.Error(b.makeLogMsg(kind, msg))
}
func (b *BaseSvc) CriticalLog(kind, msg []byte) {
b.accessLogger.Critical(b.makeLogMsg(kind, msg))
}
func (b *BaseSvc) AlertLog(kind, msg []byte) {
b.accessLogger.Alert(b.makeLogMsg(kind, msg))
}
func (b *BaseSvc) EmergencyLog(kind, msg []byte) {
b.accessLogger.Emergency(b.makeLogMsg(kind, msg))
}
func (b *BaseSvc) makeLogMsg(kind, msg []byte) []byte {
return gomisc.AppendBytes(
[]byte("["),
kind,
[]byte("]"),
[]byte("\t"),
msg,
)
}