Skip to content

Commit

Permalink
only color error log lines, not the headers
Browse files Browse the repository at this point in the history
[#126256921]
  • Loading branch information
XenoPhex committed Feb 14, 2017
1 parent a29d96d commit 9d3da9c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
9 changes: 5 additions & 4 deletions util/ui/ui.go
Expand Up @@ -251,10 +251,11 @@ func (ui *UI) DisplayLogMessage(message LogMessage, displayHeader bool) {
}

for _, line := range strings.Split(message.Message(), "\n") {
fmt.Fprintf(ui.Out, "%s%s\n",
ui.addFlavor(header, white, true),
strings.TrimRight(line, "\r\n"),
)
logLine := fmt.Sprintf("%s%s", header, strings.TrimRight(line, "\r\n"))
if message.Type() == "ERR" {
logLine = ui.addFlavor(logLine, red, false)
}
fmt.Fprintf(ui.Out, "%s\n", logLine)
}
}

Expand Down
16 changes: 13 additions & 3 deletions util/ui/ui_test.go
Expand Up @@ -445,7 +445,7 @@ some-prefixgg hh ii`))
Context("single line log message", func() {
It("prints out a single line to STDOUT", func() {
ui.DisplayLogMessage(message, true)
Expect(ui.Out).To(Say("\x1b\\[37;1m2016-07-19T16:08:12.00-0700 \\[APP/PROC/WEB/12\\] OUT \x1b\\[0mThis is a log message\n"))
Expect(ui.Out).To(Say("2016-07-19T16:08:12.00-0700 \\[APP/PROC/WEB/12\\] OUT This is a log message\n"))
})
})

Expand All @@ -460,8 +460,8 @@ some-prefixgg hh ii`))

It("prints out mutliple lines to STDOUT", func() {
ui.DisplayLogMessage(message, true)
Expect(ui.Out).To(Say("\x1b\\[37;1m2016-07-19T16:08:12.00-0700 \\[APP/PROC/WEB/12\\] OUT \x1b\\[0mThis is a log message\n"))
Expect(ui.Out).To(Say("\x1b\\[37;1m2016-07-19T16:08:12.00-0700 \\[APP/PROC/WEB/12\\] OUT \x1b\\[0mThis is also a log message\n"))
Expect(ui.Out).To(Say("2016-07-19T16:08:12.00-0700 \\[APP/PROC/WEB/12\\] OUT This is a log message\n"))
Expect(ui.Out).To(Say("2016-07-19T16:08:12.00-0700 \\[APP/PROC/WEB/12\\] OUT This is also a log message\n"))
})
})
})
Expand Down Expand Up @@ -490,5 +490,15 @@ some-prefixgg hh ii`))
})
})
})

Context("error log lines", func() {
BeforeEach(func() {
message.TypeReturns("ERR")
})
It("colors the line red", func() {
ui.DisplayLogMessage(message, false)
Expect(ui.Out).To(Say("\x1b\\[31mThis is a log message\x1b\\[0m\n"))
})
})
})
})

0 comments on commit 9d3da9c

Please sign in to comment.