Skip to content

Commit

Permalink
Add test of colors with ForceColor
Browse files Browse the repository at this point in the history
go test -v -run TestLogger/colorize
  • Loading branch information
dolmen authored and evanphx committed Dec 4, 2023
1 parent 852f2c3 commit 1ea3660
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,34 @@ func TestLogger(t *testing.T) {
assert.Equal(t, "[INFO] sublogger: this is test\n", rest)
})

t.Run("colorize", func(t *testing.T) {
var buf bytes.Buffer

logger := New(&LoggerOptions{
// No name!
Output: &buf,
Level: Trace,
Color: ForceColor,
TimeFormat: "<time>",
})

logger.Trace("trace")
logger.Debug("debug")
logger.Info("info")
logger.Warn("warn")
logger.Error("error")
str := buf.String()

assert.Equal(t, ""+
"\033[92m<time> [TRACE] trace\n\033[0m"+
"\033[97m<time> [DEBUG] debug\n\033[0m"+
"\033[94m<time> [INFO] info\n\033[0m"+
"\033[93m<time> [WARN] warn\n\033[0m"+
"\033[91m<time> [ERROR] error\n\033[0m",
str,
)
})

t.Run("use a different time format", func(t *testing.T) {
var buf bytes.Buffer

Expand Down

0 comments on commit 1ea3660

Please sign in to comment.