Skip to content

Commit a2fde75

Browse files
rabbahdgrove-oss
authored andcommitted
Fix regex for log stripping. (#462)
1 parent d0f5736 commit a2fde75

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

commands/util.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ func stripTimestamp(log string) (strippedLog string) {
277277
// the timestamp expected format is YYYY-MM-DDTHH:MM:SS.[0-9]+Z
278278
// an optional " stdout" or " stderr" stream identifier
279279
// and the rest as the log line
280-
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(.*)")
280+
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(.*)")
281281
match := regex.FindStringSubmatch(log)
282282

283283
if len(match) > 3 && len(match[3]) > 0 {

commands/util_test.go

+15-13
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,21 @@ import (
2626

2727
func TestStripTimestamp(t *testing.T) {
2828
logs := map[string]string{
29-
"2018-05-02T19:33:32.829992819Z stdout: this is stdout stderr: this is still stdout": "this is stdout stderr: this is still stdout",
30-
"2018-05-02T19:33:32.829992819Z stderr: this is stderr stdout: this is still stderr": "this is stderr stdout: this is still stderr",
31-
"2018-05-02T19:33:32.89Z stdout: this is stdout": "this is stdout",
32-
"2018-05-02T19:33:32.89Z this is a msg": "this is a msg",
33-
"2018-05-02T19:33:32.89Z this is a msg": " this is a msg",
34-
"anything stdout: this is stdout": "anything stdout: this is stdout",
35-
"anything stderr: this is stderr": "anything stderr: this is stderr",
36-
"stdout: this is stdout": "stdout: this is stdout",
37-
"stderr: this is stderr": "stderr: this is stderr",
38-
"this is stdout": "this is stdout",
39-
"this is stderr": "this is stderr",
40-
"something": "something",
41-
"": ""}
29+
"2018-05-02T19:33:32.829992819Z stdout: this is stdout stderr: this is still stdout": "this is stdout stderr: this is still stdout",
30+
"2018-05-02T19:33:32.829992819Z stderr: this is stderr stdout: this is still stderr": "this is stderr stdout: this is still stderr",
31+
"2018-05-02T19:33:32.829992819Z stdout: this is stdout stderr: this is still stdout": "this is stdout stderr: this is still stdout",
32+
"2018-05-02T19:33:32.829992819Z stderr: this is stderr stdout: this is still stderr": "this is stderr stdout: this is still stderr",
33+
"2018-05-02T19:33:32.89Z stdout: this is stdout": "this is stdout",
34+
"2018-05-02T19:33:32.89Z this is a msg": "this is a msg",
35+
"2018-05-02T19:33:32.89Z this is a msg": " this is a msg",
36+
"anything stdout: this is stdout": "anything stdout: this is stdout",
37+
"anything stderr: this is stderr": "anything stderr: this is stderr",
38+
"stdout: this is stdout": "stdout: this is stdout",
39+
"stderr: this is stderr": "stderr: this is stderr",
40+
"this is stdout": "this is stdout",
41+
"this is stderr": "this is stderr",
42+
"something": "something",
43+
"": ""}
4244
assert := assert.New(t)
4345

4446
for log, expected := range logs {

0 commit comments

Comments
 (0)