Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: omitted log messages #1706

Merged
merged 1 commit into from
Apr 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading