Skip to content

Commit

Permalink
Merge pull request #215 from dnephin/windows-color
Browse files Browse the repository at this point in the history
Fix color codes on windows
  • Loading branch information
dnephin committed Sep 4, 2021
2 parents c728c6c + 7cadea0 commit b08915a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 21 deletions.
4 changes: 2 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ func setupFlags(name string) (*pflag.FlagSet, *options) {
junitTestCaseClassnameFormat: &junitFieldFormatValue{},
junitTestSuiteNameFormat: &junitFieldFormatValue{},
postRunHookCmd: &commandValue{},
stdout: os.Stdout,
stderr: os.Stderr,
stdout: color.Output,
stderr: color.Error,
}
flags := pflag.NewFlagSet(name, pflag.ContinueOnError)
flags.SetInterspersed(false)
Expand Down
31 changes: 12 additions & 19 deletions log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package log

import (
"fmt"
"os"

"github.com/fatih/color"
)
Expand All @@ -16,15 +15,10 @@ const (
)

var (
level = WarnLevel
out stringWriter = os.Stderr
level = WarnLevel
out = color.Error
)

// TODO: replace with io.StringWriter once support for go1.11 is dropped.
type stringWriter interface {
WriteString(s string) (n int, err error)
}

// SetLevel for the global logger.
func SetLevel(l Level) {
level = l
Expand All @@ -35,36 +29,35 @@ func Warnf(format string, args ...interface{}) {
if level < WarnLevel {
return
}
out.WriteString(color.YellowString("WARN "))
out.WriteString(fmt.Sprintf(format, args...))
out.WriteString("\n")
fmt.Fprint(out, color.YellowString("WARN "))
fmt.Fprintf(out, format, args...)
fmt.Fprint(out, "\n")
}

// Debugf prints the message to stderr, with no prefix.
func Debugf(format string, args ...interface{}) {
if level < DebugLevel {
return
}
out.WriteString(fmt.Sprintf(format, args...))
out.WriteString("\n")
fmt.Fprintf(out, format, args...)
fmt.Fprint(out, "\n")
}

// Errorf prints the message to stderr, with a red ERROR prefix.
func Errorf(format string, args ...interface{}) {
if level < ErrorLevel {
return
}
out.WriteString(color.RedString("ERROR "))
out.WriteString(fmt.Sprintf(format, args...))
out.WriteString("\n")
fmt.Fprint(out, color.RedString("ERROR "))
fmt.Fprintf(out, format, args...)
fmt.Fprint(out, "\n")
}

// Error prints the message to stderr, with a red ERROR prefix.
func Error(msg string) {
if level < ErrorLevel {
return
}
out.WriteString(color.RedString("ERROR "))
out.WriteString(msg)
out.WriteString("\n")
fmt.Fprint(out, color.RedString("ERROR "))
fmt.Fprintln(out, msg)
}

0 comments on commit b08915a

Please sign in to comment.