echo icon indicating copy to clipboard operation
echo copied to clipboard

Logging level middleware

Open beykansen opened this issue 3 years ago • 1 comments

I added level field to logging template and allow customize with LevelSetter function for different use cases. For example, you can set level to info by just checking err == nil and/or you can set error when request responded with 500 and/or error is not nil.

Adding level field to logs allows better filtering and observability in your log stack.

beykansen avatar Sep 09 '22 14:09 beykansen

Maybe using https://echo.labstack.com/middleware/logger/#customizable-function-based-requestlogger would make more sense? and you could start using proper logging library like https://github.com/rs/zerolog , https://github.com/uber-go/zap etc

aldas avatar Sep 09 '22 18:09 aldas

I think this feature is covered now with https://github.com/labstack/echo/pull/2341 This PR allows you to have custom tag with callback that can access context. so you can add anything you want to logger row - single or multiple tags etc.

e.Use(middleware.LoggerWithConfig(middleware.LoggerConfig{
		Format: `{"method":"${method}",${custom}}` + "\n",
		CustomTagFunc: func(c echo.Context, buf *bytes.Buffer) (int, error) {
			return buf.WriteString(`"tag":"my-value"`)
		},
}))

aldas avatar Dec 01 '22 21:12 aldas

As discussed we will close this in favor of #2341 which is already merged.

Thanks though for this PR @beykansen and your thoughts

lammel avatar Dec 02 '22 21:12 lammel