-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
request_logger middleware - unable to log query params #2742
Comments
could you edit this example to suit your example and provide couple of CURLs to show different requests. package main
import (
"context"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"log/slog"
"net/http"
"os"
)
func main() {
e := echo.New()
logger := slog.New(slog.NewJSONHandler(os.Stdout, nil))
e.Use(middleware.RequestLoggerWithConfig(middleware.RequestLoggerConfig{
LogStatus: true,
LogURI: true,
LogError: true,
HandleError: true,
LogValuesFunc: func(c echo.Context, v middleware.RequestLoggerValues) error {
if v.Error == nil {
//test := c.Request().URL.Query().Get("test")
logger.LogAttrs(context.Background(), slog.LevelInfo, "REQUEST",
slog.String("uri", v.URI),
slog.Int("status", v.Status),
)
} else {
logger.LogAttrs(context.Background(), slog.LevelError, "REQUEST_ERROR",
slog.String("uri", v.URI),
slog.Int("status", v.Status),
slog.String("err", v.Error.Error()),
)
}
return nil
},
}))
e.GET("/", func(c echo.Context) error {
return c.String(http.StatusOK, "ok")
})
if err := e.Start(":8080"); err != nil {
slog.Error("failed to start server")
}
} |
ah thanks I didn't notice I have access to the full request through the echo Context |
no problemo :) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have the following uri format in my application:
uri=/?test132
. I would like to log the query with the RequestLogger middleware provided by this package (RequestLoggerWithConfig
) viaLogValuesFunc
and slog. Unfortunately you need to specify all the Query Parameters that should be passed toLogValuesFunc
on theLogQueryParams
attribute, but in this case the param is parsed as the query name.Please add an option to have access to all query params inside
LogValuesFunc
.The text was updated successfully, but these errors were encountered: