| 1 |
package humanlog |
| 2 |
|
| 3 |
import ( |
| 4 |
"regexp" |
| 5 |
|
| 6 |
"github.com/humanlogio/humanlog/internal/pkg/model" |
| 7 |
) |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
var dcLogsPrefixRe = regexp.MustCompile("^(?:\x1b\\[\\d+m)?(?P<service_name>[a-zA-Z0-9._-]+)\\s+\\|(?:\x1b\\[0m)? (?P<rest_of_line>.*)$") |
| 17 |
|
| 18 |
type handler interface { |
| 19 |
TryHandle([]byte, *model.Structured) bool |
| 20 |
} |
| 21 |
|
| 22 |
func tryDockerComposePrefix(d []byte, ev *model.Structured, nextHandler handler) bool { |
| 23 |
matches := dcLogsPrefixRe.FindSubmatch(d) |
| 24 |
if matches != nil { |
| 25 |
if nextHandler.TryHandle(matches[2], ev) { |
| 26 |
ev.KVs = append(ev.KVs, model.KV{ |
| 27 |
Key: "service", Value: string(matches[1]), |
| 28 |
}) |
| 29 |
return true |
| 30 |
} |
| 31 |
|
| 32 |
|
| 33 |
switch h := nextHandler.(type) { |
| 34 |
case *JSONHandler: |
| 35 |
if tryZapDevDCPrefix(matches[2], ev, h) { |
| 36 |
ev.KVs = append(ev.KVs, model.KV{ |
| 37 |
Key: "service", Value: string(matches[1]), |
| 38 |
}) |
| 39 |
return true |
| 40 |
} |
| 41 |
} |
| 42 |
} |
| 43 |
return false |
| 44 |
} |