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

Is it possible to add custom attrs from fiber context? #6

Closed stavros-k closed 11 months ago

stavros-k commented 1 year ago

For example request/response body or request ID.

Currently there is request id being added (that can be disabled). What if I want to use the request ID middleware, in order to use a custom header / generator. How I could log that?

Thanks!

samber commented 1 year ago

I suppose we can do something like that:

slogfiber.NewWithConfig(
    logger,
    slogfiber.Config{
        CustomAttrs: func (ctx *fiber.Ctx) []slog.Attr {
              .......
        },
        WithRequestBody: bool,
        WithResponseBody: bool,
    },
)

WDYT ?

stavros-k commented 1 year ago

Looks good yea

samber commented 11 months ago

Added to v1.5.0 (see readme).