mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-01 02:30:48 -05:00
25 lines
549 B
Go
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
|
|
}
|
|
}
|