Skip to content

Commit 05b6d03

Browse files
committed
Merge pull request #4442 from mboersma/fix-apps-logs-panic
fix(client): print logs that lack a category prefix
2 parents b285746 + 21fb0f7 commit 05b6d03

2 files changed

Lines changed: 29 additions & 2 deletions

File tree

client/cmd/apps.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,19 @@ func AppLogs(appID string, lines int) error {
158158
return err
159159
}
160160

161+
return printLogs(logs)
162+
}
163+
164+
// printLogs prints each log line with a color matched to its category.
165+
func printLogs(logs string) error {
161166
for _, log := range strings.Split(strings.Trim(logs, `\n`), `\n`) {
162-
catagory := strings.Split(strings.Split(log, ": ")[0], " ")[1]
167+
category := "unknown"
168+
parts := strings.Split(strings.Split(log, ": ")[0], " ")
169+
if len(parts) >= 2 {
170+
category = parts[1]
171+
}
163172
colorVars := map[string]string{
164-
"Color": chooseColor(catagory),
173+
"Color": chooseColor(category),
165174
"Log": log,
166175
}
167176
fmt.Println(prettyprint.ColorizeVars("{{.V.Color}}{{.V.Log}}{{.C.Default}}", colorVars))

client/cmd/apps_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package cmd
2+
3+
import "testing"
4+
5+
func TestPrintLogLinesBadLine(t *testing.T) {
6+
t.Parallel()
7+
8+
// Regression test for https://github.com/deis/deis/issues/4420
9+
logs := `\nDone preparing production files\n\n\u001b[4mRunning \"concat:plugins\" (concat) task\u001b[24m\n`
10+
if err := printLogs(logs); err != nil {
11+
t.Fatal(err)
12+
}
13+
14+
logs = `\n\n\n`
15+
if err := printLogs(logs); err != nil {
16+
t.Fatal(err)
17+
}
18+
}

0 commit comments

Comments
 (0)