Skip to content

Commit

Permalink
request logger: add example for Slog https://pkg.go.dev/log/slog
Browse files Browse the repository at this point in the history
  • Loading branch information
aldas committed Nov 7, 2023
1 parent 4b26cde commit c7d22a7
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions middleware/request_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,30 @@ import (
"github.com/labstack/echo/v4"
)

// Example for `slog` https://pkg.go.dev/log/slog
// logger := slog.New(slog.NewJSONHandler(os.Stdout, nil))
// e.Use(middleware.RequestLoggerWithConfig(middleware.RequestLoggerConfig{
// LogStatus: true,
// LogURI: true,
// LogError: true,
// HandleError: true, // forwards error to the global error handler, so it can decide appropriate status code
// LogValuesFunc: func(c echo.Context, v middleware.RequestLoggerValues) error {
// if v.Error == nil {
// 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
// },
// }))
//
// Example for `fmt.Printf`
// e.Use(middleware.RequestLoggerWithConfig(middleware.RequestLoggerConfig{
// LogStatus: true,
Expand Down

0 comments on commit c7d22a7

Please sign in to comment.