MCPcopy Create free account
hub / github.com/DoNewsCode/core / WithBaggage

Function WithBaggage

logging/log.go:130–142  ·  view source on GitHub ↗

WithBaggage decorates the log.Logger with information form context.

(logger log.Logger, ctx context.Context)

Source from the content-addressed store, hash-verified

128
129// WithBaggage decorates the log.Logger with information form context.
130func WithBaggage(logger log.Logger, ctx context.Context) log.Logger {
131 var args []interface{}
132
133 bag := ctxmeta.GetBaggage(ctx)
134
135 for _, kv := range bag.Slice() {
136 args = append(args, kv.Key, kv.Val)
137 }
138
139 base := log.With(logger, args...)
140
141 return base
142}
143
144type levelLogger struct {
145 log.Logger

Callers 1

WithContextFunction · 0.85

Calls 3

GetBaggageFunction · 0.92
SliceMethod · 0.80
WithMethod · 0.45

Tested by

no test coverage detected