diff --git a/pkg/util/loghelper/klog.go b/pkg/util/loghelper/klog.go index 2402c4c2b..3e23550dc 100644 --- a/pkg/util/loghelper/klog.go +++ b/pkg/util/loghelper/klog.go @@ -9,7 +9,7 @@ import ( var klogRegEx1 = regexp.MustCompile(`^[A-Z][0-9]{4} [0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{6}\s+[0-9]+\s([^]]+)] (.+)$`) -var structuredComponent = regexp.MustCompile(`^([a-zA-Z\-_]+)=`) +var structuredComponent = regexp.MustCompile(`^([a-zA-Z0-9\-_]+)=`) // https://github.com/kubernetes/community/blob/master/contributors/devel/sig-instrumentation/logging.md func PrintKlogLine(line string, args []interface{}) { @@ -30,6 +30,7 @@ func parseStructuredLogging(line string) (string, []interface{}) { } line = strings.TrimSpace(line) + originalLine := line // parse message message, line := parseQuotedMessage(line, true) @@ -42,7 +43,8 @@ func parseStructuredLogging(line string) (string, []interface{}) { retArgs := []interface{}{} for line != "" { if !structuredComponent.MatchString(line) { - break + // there seems to be a problem with parsing, so just return original line + return originalLine, nil } matches := structuredComponent.FindStringSubmatch(line) @@ -52,13 +54,12 @@ func parseStructuredLogging(line string) (string, []interface{}) { value, restOfLine := parseQuotedMessage(line, false) message = value - line = restOfLine + line = strings.TrimSpace(restOfLine) } else { retArgs = append(retArgs, name) value, restOfLine := parseQuotedMessage(line, false) - retArgs = append(retArgs, value) - - line = restOfLine + retArgs = append(retArgs, strings.TrimSpace(value)) + line = strings.TrimSpace(restOfLine) } } @@ -103,6 +104,8 @@ func parseQuotedMessage(line string, allowSpace bool) (string, string) { if nextSpace > 0 { return strings.ReplaceAll(line[:nextSpace], `\"`, `"`), line[nextSpace+1:] } + + return strings.ReplaceAll(line, `\"`, `"`), "" } return strings.ReplaceAll(message, `\"`, `"`), line