-
Notifications
You must be signed in to change notification settings - Fork 3
/
readdockercompose.go
57 lines (50 loc) · 1.07 KB
/
readdockercompose.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
package logfrog
import (
"strings"
)
type ReaderDockerCompose struct {
}
func (pr *ReaderDockerCompose) Valid(line string) bool {
if line == "" {
return false
}
parts := strings.Split(line, "|")
return len(parts) != 1
}
func (pr *ReaderDockerCompose) Read(line string) (label string, logData LogData, err error) {
return readDockerComposeLine(line)
}
// ReadDockerComposeLine reads a line from a docker-compose log output
func readDockerComposeLine(line string) (
label string,
logData LogData,
errRead error,
) {
found := false
trimmedLine := ""
label = ""
for _, r := range line {
if found {
trimmedLine += string(r)
} else {
if r == '|' {
found = true
} else {
label += string(r)
}
}
}
if !found {
logData = map[string]interface{}{"msg": "| not found"}
return
}
// bit hacky ...
trimmedLine = strings.TrimPrefix(trimmedLine, " ")
label = strings.Trim(label, " ")
_, logData, errRead = read(strings.Trim(trimmedLine, " \n"))
if errRead != nil {
logData = map[string]interface{}{"msg": trimmedLine}
errRead = nil
}
return
}