Skip to content

Commit

Permalink
Merge pull request #1706 from FabianKramm/main
Browse files Browse the repository at this point in the history
fix: omitted log messages
  • Loading branch information
FabianKramm authored Apr 19, 2024
2 parents 2589c2b + 77be83c commit 104653a
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions pkg/util/loghelper/klog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}) {
Expand All @@ -30,6 +30,7 @@ func parseStructuredLogging(line string) (string, []interface{}) {
}

line = strings.TrimSpace(line)
originalLine := line

// parse message
message, line := parseQuotedMessage(line, true)
Expand All @@ -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)
Expand All @@ -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)
}
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 104653a

Please sign in to comment.