File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ))
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments