-
Notifications
You must be signed in to change notification settings - Fork 3
/
readgograpple.go
48 lines (43 loc) · 978 Bytes
/
readgograpple.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
package logfrog
import (
"encoding/json"
)
type ReaderGograpple struct{}
func (pr *ReaderGograpple) Valid(line string) bool {
if line == "" {
return false
}
return []byte(line)[0] == byte('{')
}
func (pr *ReaderGograpple) Read(line string) (label string, logData LogData, err error) {
return readGograppleLine(line)
}
func readGograppleLine(line string) (label string, logData LogData, err error) {
logData = LogData{}
errParse := json.Unmarshal([]byte(line), &logData)
if errParse != nil {
err = errParse
return
}
msg, okMSGOk := logData["msg"]
if okMSGOk {
switch t := msg.(type) {
case string:
label = "dlv"
msgString := t
if len(msgString) > 2 {
msgBytes := []byte(msgString)
if msgBytes[0] == '{' && msgBytes[len(msgBytes)-1] == '}' {
label = "process"
logData = LogData{}
errParse := json.Unmarshal(msgBytes, &logData)
if errParse != nil {
err = errParse
return
}
}
}
}
}
return
}