diff --git a/console.go b/console.go index e66d8886..28279885 100644 --- a/console.go +++ b/console.go @@ -313,7 +313,7 @@ func needsQuote(s string) bool { // colorize returns the string s wrapped in ANSI code c, unless disabled is true. func colorize(s interface{}, c int, disabled bool) string { e := os.Getenv("NO_COLOR") - if e == "true" { + if e != "" { disabled = true } diff --git a/console_test.go b/console_test.go index 6460c8fe..0265672d 100644 --- a/console_test.go +++ b/console_test.go @@ -105,7 +105,7 @@ func TestConsoleWriter(t *testing.T) { }) t.Run("NO_COLOR = true", func(t *testing.T) { - os.Setenv("NO_COLOR", "true") + os.Setenv("NO_COLOR", "anything") buf := &bytes.Buffer{} w := zerolog.ConsoleWriter{Out: buf} @@ -123,25 +123,6 @@ func TestConsoleWriter(t *testing.T) { os.Unsetenv("NO_COLOR") }) - t.Run("NO_COLOR = false", func(t *testing.T) { - os.Setenv("NO_COLOR", "false") - - buf := &bytes.Buffer{} - w := zerolog.ConsoleWriter{Out: buf} - - _, err := w.Write([]byte(`{"level": "warn", "message": "Foobar"}`)) - if err != nil { - t.Errorf("Unexpected error when writing output: %s", err) - } - - expectedOutput := "\x1b[90m\x1b[0m \x1b[31mWRN\x1b[0m Foobar\n" - actualOutput := buf.String() - if actualOutput != expectedOutput { - t.Errorf("Unexpected output %q, want: %q", actualOutput, expectedOutput) - } - os.Unsetenv("NO_COLOR") - }) - t.Run("Write fields", func(t *testing.T) { buf := &bytes.Buffer{} w := zerolog.ConsoleWriter{Out: buf, NoColor: true}