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)
| 67 | // within the context. If the context doesn't have a logger, the fallback |
| 68 | // logger is used. |
| 69 | func 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. |