Skip to content

Commit 1ea3660

Browse files
dolmenevanphx
authored andcommitted
Add test of colors with ForceColor
go test -v -run TestLogger/colorize
1 parent 852f2c3 commit 1ea3660

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

logger_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,34 @@ func TestLogger(t *testing.T) {
257257
assert.Equal(t, "[INFO] sublogger: this is test\n", rest)
258258
})
259259

260+
t.Run("colorize", func(t *testing.T) {
261+
var buf bytes.Buffer
262+
263+
logger := New(&LoggerOptions{
264+
// No name!
265+
Output: &buf,
266+
Level: Trace,
267+
Color: ForceColor,
268+
TimeFormat: "<time>",
269+
})
270+
271+
logger.Trace("trace")
272+
logger.Debug("debug")
273+
logger.Info("info")
274+
logger.Warn("warn")
275+
logger.Error("error")
276+
str := buf.String()
277+
278+
assert.Equal(t, ""+
279+
"\033[92m<time> [TRACE] trace\n\033[0m"+
280+
"\033[97m<time> [DEBUG] debug\n\033[0m"+
281+
"\033[94m<time> [INFO] info\n\033[0m"+
282+
"\033[93m<time> [WARN] warn\n\033[0m"+
283+
"\033[91m<time> [ERROR] error\n\033[0m",
284+
str,
285+
)
286+
})
287+
260288
t.Run("use a different time format", func(t *testing.T) {
261289
var buf bytes.Buffer
262290

0 commit comments

Comments
 (0)