diff --git a/console.go b/console.go index e13d419..90829b0 100644 --- a/console.go +++ b/console.go @@ -13,11 +13,6 @@ import ( "time" ) -const ( - colorBold = iota + 1 - colorFaint -) - const ( colorBlack = iota + 30 colorRed @@ -27,6 +22,9 @@ const ( colorMagenta colorCyan colorWhite + + colorBold = 1 + colorDarkGray = 90 ) var ( @@ -299,7 +297,7 @@ func consoleDefaultFormatTimestamp(timeFormat string, noColor bool) Formatter { case json.Number: t = tt.String() } - return colorize(t, colorFaint, noColor) + return colorize(t, colorDarkGray, noColor) } } @@ -342,7 +340,7 @@ func consoleDefaultFormatCaller(noColor bool) Formatter { c = strings.TrimPrefix(c, cwd) c = strings.TrimPrefix(c, "/") } - c = colorize(c, colorBold, noColor) + colorize(" >", colorFaint, noColor) + c = colorize(c, colorBold, noColor) + colorize(" >", colorCyan, noColor) } return c } @@ -354,7 +352,7 @@ func consoleDefaultFormatMessage(i interface{}) string { func consoleDefaultFormatFieldName(noColor bool) Formatter { return func(i interface{}) string { - return colorize(fmt.Sprintf("%s=", i), colorFaint, noColor) + return colorize(fmt.Sprintf("%s=", i), colorCyan, noColor) } } diff --git a/console_test.go b/console_test.go index 5bdfdaa..2ff2a43 100644 --- a/console_test.go +++ b/console_test.go @@ -97,7 +97,7 @@ func TestConsoleWriter(t *testing.T) { t.Errorf("Unexpected error when writing output: %s", err) } - expectedOutput := "\x1b[2m\x1b[0m \x1b[31mWRN\x1b[0m Foobar\n" + 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) @@ -121,6 +121,22 @@ func TestConsoleWriter(t *testing.T) { } }) + t.Run("Write colorized fields", func(t *testing.T) { + buf := &bytes.Buffer{} + w := zerolog.ConsoleWriter{Out: buf, NoColor: false} + + _, err := w.Write([]byte(`{"level" : "warn", "message" : "Foobar", "foo": "bar"}`)) + if err != nil { + t.Errorf("Unexpected error when writing output: %s", err) + } + + expectedOutput := "\x1b[90m\x1b[0m \x1b[31mWRN\x1b[0m Foobar \x1b[36mfoo=\x1b[0mbar\n" + actualOutput := buf.String() + if actualOutput != expectedOutput { + t.Errorf("Unexpected output %q, want: %q", actualOutput, expectedOutput) + } + }) + t.Run("Write error field", func(t *testing.T) { buf := &bytes.Buffer{} w := zerolog.ConsoleWriter{Out: buf, NoColor: true}