This repository has been archived by the owner on Nov 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.go
65 lines (53 loc) · 1.37 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
package plugin
import (
"fmt"
"github.com/iyear/go-plugin-grpc/internal/pb"
"google.golang.org/protobuf/proto"
"log"
)
func (l *Logger) Debug(v ...interface{}) {
l.log(pb.LogLevel_Debug, fmt.Sprint(v...))
}
func (l *Logger) Info(v ...interface{}) {
l.log(pb.LogLevel_Info, fmt.Sprint(v...))
}
func (l *Logger) Warn(v ...interface{}) {
l.log(pb.LogLevel_Warn, fmt.Sprint(v...))
}
func (l *Logger) Error(v ...interface{}) {
l.log(pb.LogLevel_Error, fmt.Sprint(v...))
}
func (l *Logger) Debugf(format string, v ...interface{}) {
l.log(pb.LogLevel_Debug, fmt.Sprintf(format, v...))
}
func (l *Logger) Infof(format string, v ...interface{}) {
l.log(pb.LogLevel_Info, fmt.Sprintf(format, v...))
}
func (l *Logger) Warnf(format string, v ...interface{}) {
l.log(pb.LogLevel_Warn, fmt.Sprintf(format, v...))
}
func (l *Logger) Errorf(format string, v ...interface{}) {
l.log(pb.LogLevel_Error, fmt.Sprintf(format, v...))
}
func (l *Logger) log(level pb.LogLevel, message string) {
if l.plugin.opts.LogLevel > LogLevel(level) {
return
}
b, err := proto.Marshal(&pb.LogInfo{
Type: level,
Message: message,
})
if err != nil {
log.Println(err)
return
}
err = l.plugin.clients.comm.Send(&pb.CommunicateMsg{
Type: pb.CommunicateType_Log,
Data: b,
})
if err != nil {
// 发不过去就先本机打日志
log.Printf("can't send log to core: %v", err)
return
}
}