Initial QSfera import
This commit is contained in:
+24
@@ -0,0 +1,24 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user