samber / slog-fiber

🚨 Fiber middleware for slog logger
https://pkg.go.dev/github.com/samber/slog-fiber
MIT License
53 stars 9 forks source link

Default log level for 4XX ERROR status is WARN. #15

Closed wathuta closed 8 months ago

wathuta commented 9 months ago

The default level for error status 400,404,422 is WARN. How can i dynamically set the level of other status a part from 200 to be ERROR? Here's my log configuration

l := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{AddSource: true, Level: &slog.LevelVar{}}))

s.app.Use(
    slogfiber.New(l)
)
samber commented 8 months ago

You can use:

config := slogfiber.Config{
    DefaultLevel:     slog.LevelInfo,
    ClientErrorLevel: slog.LevelWarn,
    ServerErrorLevel: slog.LevelError,
}

app := fiber.New()
app.Use(slogfiber.NewWithConfig(logger, config))

I just added these parameters to the readme.