Skip to content

Commit

Permalink
Fix regex for log stripping. (#462)
Browse files Browse the repository at this point in the history
  • Loading branch information
rabbah authored and dgrove-oss committed Nov 1, 2019
1 parent d0f5736 commit a2fde75
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
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

0 comments on commit a2fde75

Please sign in to comment.