logging

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewContextWithLogger

func NewContextWithLogger(
	ctx context.Context,
	cfg config.Config,
	otelLoggerProvider *log.LoggerProvider,
) context.Context

NewContextWithLogger creates a new context with a configured logger. If otelLoggerProvider is provided, logs will be sent to both local output and OTel collector. If otelLoggerProvider is nil, only local logging is configured (useful for tests and local dev without OTel).

func NewLoggerProvider added in v0.2.0

func NewLoggerProvider(
	ctx context.Context,
	opts telemetry.Options,
) (*log.LoggerProvider, telemetry.ShutdownFunc, error)

NewLoggerProvider creates and configures a new OpenTelemetry LoggerProvider with OTLP HTTP exporter. Returns the logger provider, a shutdown function that should be called when the application exits, and an error if initialization fails.

The logger provider is automatically set as the global provider and can be used with otelslog bridge.

Types

type CustomHandler

type CustomHandler struct {
	slog.Handler
}

func (*CustomHandler) Enabled

func (h *CustomHandler) Enabled(ctx context.Context, level slog.Level) bool

func (*CustomHandler) Handle

func (h *CustomHandler) Handle(ctx context.Context, r slog.Record) error

func (*CustomHandler) WithAttrs

func (h *CustomHandler) WithAttrs(attrs []slog.Attr) slog.Handler

func (*CustomHandler) WithGroup

func (h *CustomHandler) WithGroup(name string) slog.Handler

type MultiHandler added in v0.2.0

type MultiHandler struct {
	// contains filtered or unexported fields
}

MultiHandler forwards log records to multiple handlers. This allows logs to be sent to both local output (stdout/prettylog) and OTel collector.

func NewMultiHandler added in v0.2.0

func NewMultiHandler(handlers ...slog.Handler) *MultiHandler

NewMultiHandler creates a new MultiHandler that forwards records to all provided handlers.

func (*MultiHandler) Enabled added in v0.2.0

func (h *MultiHandler) Enabled(ctx context.Context, level slog.Level) bool

Enabled returns true if any of the handlers are enabled for the given level.

func (*MultiHandler) Handle added in v0.2.0

func (h *MultiHandler) Handle(ctx context.Context, r slog.Record) error

Handle forwards the record to all handlers.

func (*MultiHandler) WithAttrs added in v0.2.0

func (h *MultiHandler) WithAttrs(attrs []slog.Attr) slog.Handler

WithAttrs returns a new MultiHandler with the given attributes added to all handlers.

func (*MultiHandler) WithGroup added in v0.2.0

func (h *MultiHandler) WithGroup(name string) slog.Handler

WithGroup returns a new MultiHandler with the given group added to all handlers.

Jump to

Keyboard shortcuts

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