This project is archived in favor of the official Fiber slog middleware:
This package remains here for existing users, but new projects should prefer the official package above.
It is an opinionated Fiber request logger middleware using slog.
It allows adding attributes from anywhere within the handler.
Registering middleware with custom config:
app.Use(logger.New(logger.Config{
// skip logger with filter
Filter: func(ctx *fiber.Ctx) bool {
return ctx.Path() == "/exclude"
},
// customize attributes with builtin tag
BuiltinAttrs []string{PathTag,StatusTag}
// adding custom attributes with custom function
CustomAttr: []logger.CustomFunc{
func(c *fiber.Ctx, r *slog.Record, e error) {
r.AddAttrs(slog.String("custom_key", "custom_value"))
},
},
// assign slog logger
Logger: slog.Default(),
}))Adding extra attributes from anywhere within a handler:
router.Post("/", func(ctx *fiber.Ctx) error {
...
logger.AddAttrs(ctx, slog.Any("params", params))
logger.Add(ctx, "params", params))
...
})