Skip to content
This repository was archived by the owner on May 28, 2026. It is now read-only.

chazuka/fiber-slogger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Archived

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.

Usage

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))
    ...
})

About

Fiber request logger middleware using slog

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages