blob: 433eb5f15e5f66fca119f95fc9c9243715c779ce (
plain)
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
|
package logformat
import (
"strings"
"github.com/mimecast/dtail/internal/protocol"
)
// MakeFieldsGENERIGKV is the generic key-value logfile parser.
func (p *Parser) MakeFieldsGENERIGKV(maprLine string) (map[string]string, error) {
splitted := strings.Split(maprLine, protocol.FieldDelimiter)
fields := make(map[string]string, len(splitted))
fields["*"] = "*"
fields["$line"] = maprLine
fields["$empty"] = ""
fields["$hostname"] = p.hostname
fields["$timezone"] = p.timeZoneName
fields["$timeoffset"] = p.timeZoneOffset
for _, kv := range splitted[0:] {
keyAndValue := strings.SplitN(kv, "=", 2)
if len(keyAndValue) != 2 {
//dlog.Common.Debug("Unable to parse key-value token, ignoring it", kv)
continue
}
fields[strings.ToLower(keyAndValue[0])] = keyAndValue[1]
}
return fields, nil
}
|