You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openwhisk.apache.org by GitBox <gi...@apache.org> on 2018/05/08 19:46:28 UTC

[GitHub] mdeuser closed pull request #292: Account for variable length timestamps when stripping logs

mdeuser closed pull request #292: Account for variable length timestamps when stripping logs
URL: https://github.com/apache/incubator-openwhisk-cli/pull/292
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/commands/activation.go b/commands/activation.go
index a360270f..dcf1ffa9 100644
--- a/commands/activation.go
+++ b/commands/activation.go
@@ -202,7 +202,12 @@ var activationLogsCmd = &cobra.Command{
 			return werr
 		}
 
-		printActivationLogs(activation.Logs)
+		if !Flags.activation.strip {
+			printActivationLogs(activation.Logs)
+		} else {
+			printStrippedActivationLogs(activation.Logs)
+		}
+
 		return nil
 	},
 }
diff --git a/commands/util.go b/commands/util.go
index 570a93eb..a33ad23d 100644
--- a/commands/util.go
+++ b/commands/util.go
@@ -225,6 +225,19 @@ func makeDefaultHeader(collection interface{}) string {
 	return defaultHeader
 }
 
+func stripTimestamp(log string) (strippedLog string) {
+	regex := regexp.MustCompile("[a-zA-Z0-9\\s]*(stdout|stderr):\\s(.*)")
+	match := regex.FindStringSubmatch(log)
+
+	if len(match) > 2 && len(match[2]) > 0 {
+		strippedLog = match[2]
+	} else {
+		strippedLog = log
+	}
+
+	return strippedLog
+}
+
 func printFullList(collection interface{}) {
 	switch collection := collection.(type) {
 	case []whisk.Action:
@@ -280,14 +293,15 @@ func printFullActivationList(activations []whisk.Activation) {
 	}
 }
 
-func printActivationLogs(logs []string) {
+func printStrippedActivationLogs(logs []string) {
 	for _, log := range logs {
-		if Flags.activation.strip {
-			fmt.Printf("%s\n", log[39:])
-		} else {
-			fmt.Printf("%s\n", log)
-		}
+		fmt.Printf("%s\n", stripTimestamp(log))
+	}
+}
 
+func printActivationLogs(logs []string) {
+	for _, log := range logs {
+		fmt.Printf("%s\n", log)
 	}
 }
 
diff --git a/commands/util_test.go b/commands/util_test.go
new file mode 100644
index 00000000..afdba359
--- /dev/null
+++ b/commands/util_test.go
@@ -0,0 +1,46 @@
+//// +build unit
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package commands
+
+import (
+	"github.com/stretchr/testify/assert"
+	"testing"
+)
+
+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 stderr: this is stderr":                                     "this is stderr",
+		"anything stdout: this is stdout":                                                    "this is stdout",
+		"anything stderr: this is stderr":                                                    "this is stderr",
+		"stdout: this is stdout":                                                             "this is stdout",
+		"stderr: this is 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 {
+		assert.Equal(stripTimestamp(log), expected)
+	}
+}


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services