MCPcopy Create free account
hub / github.com/cortexproject/cortex / FromContextWithFallback

Function FromContextWithFallback

pkg/util/spanlogger/spanlogger.go:69–82  ·  view source on GitHub ↗

FromContextWithFallback returns a span logger using the current parent span. IF there is no parent span, the SpanLogger will only log to the logger within the context. If the context doesn't have a logger, the fallback logger is used.

(ctx context.Context, fallback log.Logger)

Source from the content-addressed store, hash-verified

67// within the context. If the context doesn't have a logger, the fallback
68// logger is used.
69func FromContextWithFallback(ctx context.Context, fallback log.Logger) *SpanLogger {
70 logger, ok := ctx.Value(loggerCtxKey).(log.Logger)
71 if !ok {
72 logger = fallback
73 }
74 sp := opentracing.SpanFromContext(ctx)
75 if sp == nil {
76 sp = defaultNoopSpan
77 }
78 return &SpanLogger{
79 Logger: util_log.WithContext(ctx, logger),
80 Span: sp,
81 }
82}
83
84// Log implements gokit's Logger interface; sends logs to underlying logger and
85// also puts the on the spans.

Callers 2

FromContextFunction · 0.85

Calls 1

ValueMethod · 0.45

Tested by 1