Files
opencloud/vendor/github.com/samber/slog-common/context.go
Ralf Haferkamp e85d8effc1 Bump reva
Fixes: #1871, #1867
2025-11-20 14:58:30 +01:00

25 lines
549 B
Go

package slogcommon
import (
"context"
"log/slog"
)
func ContextExtractor(ctx context.Context, fns []func(ctx context.Context) []slog.Attr) []slog.Attr {
attrs := []slog.Attr{}
for _, fn := range fns {
attrs = append(attrs, fn(ctx)...)
}
return attrs
}
func ExtractFromContext(keys ...any) func(ctx context.Context) []slog.Attr {
return func(ctx context.Context) []slog.Attr {
attrs := make([]slog.Attr, 0, len(keys))
for _, key := range keys {
attrs = append(attrs, slog.Any(key.(string), ctx.Value(key)))
}
return attrs
}
}