From 867204adfb9d5e203fed1443dc7b3c270c1adaba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arturo=20Filast=C3=B2?= Date: Thu, 13 Sep 2018 15:59:29 +0200 Subject: [PATCH] Improve the testKeys logging --- internal/log/handlers/cli/measurements.go | 32 +++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/internal/log/handlers/cli/measurements.go b/internal/log/handlers/cli/measurements.go index e3c4f0c..85dca51 100644 --- a/internal/log/handlers/cli/measurements.go +++ b/internal/log/handlers/cli/measurements.go @@ -1,6 +1,8 @@ package cli import ( + "bytes" + "encoding/json" "fmt" "io" "strings" @@ -16,6 +18,28 @@ func statusIcon(ok bool) string { } return "❌" } + +func logTestKeys(w io.Writer, testKeys string) error { + colWidth := 24 + + var out bytes.Buffer + if err := json.Indent(&out, []byte(testKeys), "", " "); err != nil { + return err + } + + testKeysLines := strings.Split(string(out.Bytes()), "\n") + if len(testKeysLines) > 1 { + testKeysLines = testKeysLines[1 : len(testKeysLines)-1] + testKeysLines[0] = "{" + testKeysLines[0][1:] + testKeysLines[len(testKeysLines)-1] = testKeysLines[len(testKeysLines)-1] + "}" + } + for _, line := range testKeysLines { + fmt.Fprintf(w, fmt.Sprintf("│ %s │\n", + util.RightPad(line, colWidth*2))) + } + return nil +} + func logMeasurementItem(w io.Writer, f log.Fields) error { colWidth := 24 @@ -60,12 +84,16 @@ func logMeasurementItem(w io.Writer, f log.Fields) error { util.RightPad(testName, colWidth), util.RightPad(anomalyStr, colWidth))) - fmt.Fprintf(w, fmt.Sprintf("│ %s │\n", - util.RightPad(testKeys, colWidth*2))) fmt.Fprintf(w, fmt.Sprintf("│ %s %s│\n", util.RightPad(failureStr, colWidth), util.RightPad(uploadStr, colWidth))) + if testKeys != "" { + if err := logTestKeys(w, testKeys); err != nil { + return err + } + } + if isLast { fmt.Fprintf(w, "└┬────────────────────────────────────────────────┬┘\n") }