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 regex for log stripping. #462

Merged
merged 1 commit into from
Nov 1, 2019
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion commands/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ func stripTimestamp(log string) (strippedLog string) {
// the timestamp expected format is YYYY-MM-DDTHH:MM:SS.[0-9]+Z
// an optional " stdout" or " stderr" stream identifier
// and the rest as the log line
regex := regexp.MustCompile("\\d{4}-[01]{1}\\d{1}-[0-3]{1}\\d{1}T[0-2]{1}\\d{1}:[0-6]{1}\\d{1}:[0-6]{1}\\d{1}.\\d+Z( (stdout|stderr):)?\\s(.*)")
regex := regexp.MustCompile("\\d{4}-[01]{1}\\d{1}-[0-3]{1}\\d{1}T[0-2]{1}\\d{1}:[0-6]{1}\\d{1}:[0-6]{1}\\d{1}.\\d+Z( *(stdout|stderr):)?\\s(.*)")
match := regex.FindStringSubmatch(log)

if len(match) > 3 && len(match[3]) > 0 {
Expand Down
28 changes: 15 additions & 13 deletions commands/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,21 @@ import (

func TestStripTimestamp(t *testing.T) {
logs := map[string]string{
"2018-05-02T19:33:32.829992819Z stdout: this is stdout stderr: this is still stdout": "this is stdout stderr: this is still stdout",
"2018-05-02T19:33:32.829992819Z stderr: this is stderr stdout: this is still stderr": "this is stderr stdout: this is still stderr",
"2018-05-02T19:33:32.89Z stdout: this is stdout": "this is stdout",
"2018-05-02T19:33:32.89Z this is a msg": "this is a msg",
"2018-05-02T19:33:32.89Z this is a msg": " this is a msg",
"anything stdout: this is stdout": "anything stdout: this is stdout",
"anything stderr: this is stderr": "anything stderr: this is stderr",
"stdout: this is stdout": "stdout: this is stdout",
"stderr: this is stderr": "stderr: this is stderr",
"this is stdout": "this is stdout",
"this is stderr": "this is stderr",
"something": "something",
"": ""}
"2018-05-02T19:33:32.829992819Z stdout: this is stdout stderr: this is still stdout": "this is stdout stderr: this is still stdout",
"2018-05-02T19:33:32.829992819Z stderr: this is stderr stdout: this is still stderr": "this is stderr stdout: this is still stderr",
"2018-05-02T19:33:32.829992819Z stdout: this is stdout stderr: this is still stdout": "this is stdout stderr: this is still stdout",
"2018-05-02T19:33:32.829992819Z stderr: this is stderr stdout: this is still stderr": "this is stderr stdout: this is still stderr",
"2018-05-02T19:33:32.89Z stdout: this is stdout": "this is stdout",
"2018-05-02T19:33:32.89Z this is a msg": "this is a msg",
"2018-05-02T19:33:32.89Z this is a msg": " this is a msg",
"anything stdout: this is stdout": "anything stdout: this is stdout",
"anything stderr: this is stderr": "anything stderr: this is stderr",
"stdout: this is stdout": "stdout: this is stdout",
"stderr: this is stderr": "stderr: this is stderr",
"this is stdout": "this is stdout",
"this is stderr": "this is stderr",
"something": "something",
"": ""}
assert := assert.New(t)

for log, expected := range logs {
Expand Down