Logging level middleware
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.
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
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"`)
},
}))
As discussed we will close this in favor of #2341 which is already merged.
Thanks though for this PR @beykansen and your thoughts