echo icon indicating copy to clipboard operation
echo copied to clipboard

how to disable the stdout log color?

Open YANGJINJUE opened this issue 4 years ago • 5 comments

how to disable the request url log color

Checklist

  • [ ] Dependencies installed
  • [ ] No typos
  • [ ] Searched existing issues and docs

Expected behaviour

if request success stdout print 200

Actual behaviour

if request success stdout will print 32m200

Steps to reproduce

e.Use(middleware.Logger())

Working code to debug


import (
  "net/http"
  "github.com/labstack/echo/v4"
  "github.com/labstack/echo/v4/middleware"
)

func main() {
  // Echo instance
  e := echo.New()

  // Middleware
  e.Use(middleware.Logger())
  e.Use(middleware.Recover())

  // Routes
  e.GET("/", hello)

  // Start server
  e.Logger.Fatal(e.Start(":1323"))
}

// Handler
func hello(c echo.Context) error {
  return c.String(http.StatusOK, "Hello, World!")
}

Version/commit

YANGJINJUE avatar May 11 '21 06:05 YANGJINJUE

Currently there is not way to disable colorerin logger middleware

Code: https://github.com/labstack/echo/blob/2acb24adb0fd619dc3c672d7fdde25c2c21061d7/middleware/logger.go#L100

aldas avatar May 11 '21 06:05 aldas

I'd also prefer to be able to disable coloring of output, so a PR would be welcome. Colored log output is nice for the developer but usually not need in production (we are gathering logs to a central server, so coloring is more of a pain than helpful).

lammel avatar May 25 '21 13:05 lammel

In that case I would remove coloring altogether. Adding another boolean or something like that would make just API more complex.

In my personal opinion - coloring of output is nice (cool effect) for demoing application startup and has little or no value for actual production environment.

most of the time I start Echo with echo.HideBanner and echo.HidePort and have custom statement to log version+address/port separately. so log rows end up in journald and other destinations in structured format (i'm using zerolog) and same for access log.

aldas avatar May 25 '21 13:05 aldas

Seems like we have exactly the same issues with coloring in logging. And I take the exact same actions. So I'm actually in favor of removing coloring too.

Maybe @pafuent and @vishr or other can show their opinion and others can 👍🏼 (to remove coloring) or 👎🏼 (to keep coloring) in the above post by @aldas .

lammel avatar May 25 '21 14:05 lammel

Logging is overhauled with v5 with no colored output, so we can probably close this issue when we release v5.

lammel avatar Mar 05 '22 20:03 lammel