Skip to content

Commit fbc4a7a

Browse files
anjannathgbraad
authored andcommitted
Issue #376 Fix colored log output for windows
This issue comes from logrus, see sirupsen/logrus#379 but as a workaround as mentioned in the above issue we can use the `go-colorable` package's writer.
1 parent 5cb43af commit fbc4a7a

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ require (
1111
github.com/docker/go-units v0.4.0
1212
github.com/inconshreveable/mousetrap v1.0.0 // indirect
1313
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0
14+
github.com/mattn/go-colorable v0.0.9
1415
github.com/pborman/uuid v1.2.0
1516
github.com/pkg/errors v0.8.1
1617
github.com/sirupsen/logrus v1.4.1

pkg/crc/logging/stderr_hook.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ package logging
33
import (
44
"io"
55
"os"
6+
"runtime"
67

8+
"github.com/mattn/go-colorable"
79
"github.com/sirupsen/logrus"
810
)
911

@@ -15,6 +17,14 @@ type stdErrHook struct {
1517
}
1618

1719
func newstdErrHook(level logrus.Level, formatter logrus.Formatter) *stdErrHook {
20+
// For windows to display colors we need to use the go-colorable writer
21+
if runtime.GOOS == "windows" {
22+
return &stdErrHook{
23+
stderr: colorable.NewColorableStderr(),
24+
formatter: formatter,
25+
level: level,
26+
}
27+
}
1828
return &stdErrHook{
1929
stderr: os.Stderr,
2030
formatter: formatter,

pkg/crc/logging/stdout_hook.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ package logging
33
import (
44
"io"
55
"os"
6+
"runtime"
67

8+
"github.com/mattn/go-colorable"
79
"github.com/sirupsen/logrus"
810
)
911

@@ -15,6 +17,14 @@ type stdOutHook struct {
1517
}
1618

1719
func newstdOutHook(level logrus.Level, formatter logrus.Formatter) *stdOutHook {
20+
// For windows to display colors we need to use the go-colorable writer
21+
if runtime.GOOS == "windows" {
22+
return &stdOutHook{
23+
stdout: colorable.NewColorableStdout(),
24+
formatter: formatter,
25+
level: level,
26+
}
27+
}
1828
return &stdOutHook{
1929
stdout: os.Stdout,
2030
formatter: formatter,

vendor/modules.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ github.com/code-ready/clicumber/testsuite
1111
github.com/code-ready/clicumber/util
1212
# github.com/code-ready/goodhosts v0.0.0-20190712111040-f090f3f77c26
1313
github.com/code-ready/goodhosts
14+
# github.com/code-ready/machine v0.0.0-20190731093717-b6d974ad44d0
1415
github.com/code-ready/machine/libmachine/state
1516
github.com/code-ready/machine/libmachine/drivers
1617
github.com/code-ready/machine/libmachine

0 commit comments

Comments
 (0)