Help us shape the future of Go! Take the 2026 Go Developer Survey

spanlogger

package
v1.21.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 5, 2026 License: Apache-2.0 Imports: 8 Imported by: 52

Documentation

Index

Constants

View Source
const (
	TenantIDTagName = "tenant_ids"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type SpanLogger

type SpanLogger struct {
	log.Logger
	opentracing.Span
}

SpanLogger unifies tracing and logging, to reduce repetition.

func FromContext added in v0.7.0

func FromContext(ctx context.Context) *SpanLogger

FromContext returns a span logger using the current parent span. If there is no parent span, the SpanLogger will only log to the logger in the context. If the context doesn't have a logger, the global logger is used.

func FromContextWithFallback added in v1.6.0

func FromContextWithFallback(ctx context.Context, fallback log.Logger) *SpanLogger

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.

func New

func New(ctx context.Context, method string, kvps ...any) (*SpanLogger, context.Context)

New makes a new SpanLogger, where logs will be sent to the global logger.

func NewWithLogger added in v1.6.0

func NewWithLogger(ctx context.Context, l log.Logger, method string, kvps ...any) (*SpanLogger, context.Context)

NewWithLogger makes a new SpanLogger with a custom log.Logger to send logs to. The provided context will have the logger attached to it and can be retrieved with FromContext or FromContextWithFallback.

func (*SpanLogger) Error

func (s *SpanLogger) Error(err error) error

Error sets error flag and logs the error on the span, if non-nil. Returns the err passed in.

func (*SpanLogger) Log

func (s *SpanLogger) Log(kvps ...any) error

Log implements gokit's Logger interface; sends logs to underlying logger and also puts the on the spans.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL