Skip to content

Commit

Permalink
Merge pull request deis#4442 from mboersma/fix-apps-logs-panic
Browse files Browse the repository at this point in the history
fix(client): print logs that lack a category prefix
  • Loading branch information
mboersma committed Sep 10, 2015
2 parents b285746 + 21fb0f7 commit 05b6d03
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
13 changes: 11 additions & 2 deletions client/cmd/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,19 @@ func AppLogs(appID string, lines int) error {
return err
}

return printLogs(logs)
}

// printLogs prints each log line with a color matched to its category.
func printLogs(logs string) error {
for _, log := range strings.Split(strings.Trim(logs, `\n`), `\n`) {
catagory := strings.Split(strings.Split(log, ": ")[0], " ")[1]
category := "unknown"
parts := strings.Split(strings.Split(log, ": ")[0], " ")
if len(parts) >= 2 {
category = parts[1]
}
colorVars := map[string]string{
"Color": chooseColor(catagory),
"Color": chooseColor(category),
"Log": log,
}
fmt.Println(prettyprint.ColorizeVars("{{.V.Color}}{{.V.Log}}{{.C.Default}}", colorVars))
Expand Down
18 changes: 18 additions & 0 deletions client/cmd/apps_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package cmd

import "testing"

func TestPrintLogLinesBadLine(t *testing.T) {
t.Parallel()

// Regression test for https://github.com/deis/deis/issues/4420
logs := `\nDone preparing production files\n\n\u001b[4mRunning \"concat:plugins\" (concat) task\u001b[24m\n`
if err := printLogs(logs); err != nil {
t.Fatal(err)
}

logs = `\n\n\n`
if err := printLogs(logs); err != nil {
t.Fatal(err)
}
}

0 comments on commit 05b6d03

Please sign in to comment.