1
0
mirror of https://github.com/labstack/echo.git synced 2025-09-16 09:16:29 +02:00

Properly disable colors in Logger middleware

Fix bug when colours are enabled if non-os.File writer is used as
output io.Writer.
This commit is contained in:
Victor Gaydov
2016-04-11 21:47:54 +03:00
committed by Vishal Rana
parent 01ac846770
commit f8117ac7b3

View File

@@ -70,7 +70,7 @@ func LoggerWithConfig(config LoggerConfig) echo.MiddlewareFunc {
config.template = fasttemplate.New(config.Format, "${", "}")
config.color = color.New()
if w, ok := config.Output.(*os.File); ok && !isatty.IsTerminal(w.Fd()) {
if w, ok := config.Output.(*os.File); !ok || !isatty.IsTerminal(w.Fd()) {
config.color.Disable()
}
@@ -110,14 +110,14 @@ func LoggerWithConfig(config LoggerConfig) echo.MiddlewareFunc {
return w.Write([]byte(p))
case "status":
n := rs.Status()
s := color.Green(n)
s := config.color.Green(n)
switch {
case n >= 500:
s = color.Red(n)
s = config.color.Red(n)
case n >= 400:
s = color.Yellow(n)
s = config.color.Yellow(n)
case n >= 300:
s = color.Cyan(n)
s = config.color.Cyan(n)
}
return w.Write([]byte(s))
case "response_time":