Documentation
¶
Overview ¶
Package slogx provides additional helpers for log/slog consumers.
Index ¶
- Constants
- func Config(conf any) slog.Attr
- func Err(err error) slog.Attr
- func FromContext(ctx context.Context) *slog.Logger
- func HealthStatus(status fmt.Stringer) slog.Attr
- func IntoContext(ctx context.Context, logger *slog.Logger) context.Context
- func Panic(val any) slog.Attr
- func RPCMethod(method string) slog.Attr
- func RPCService(service string) slog.Attr
- func RPCSystem(system string) slog.Attr
- func ResourceID(id fmt.Stringer) slog.Attr
- func ResourceName(name string) slog.Attr
- func Sampled(span trace.Span) slog.Attr
- func SpanID(span trace.Span) slog.Attr
- func Stacktrace() slog.Attr
- func Subject(subject string) slog.Attr
- func TraceID(span trace.Span) slog.Attr
Constants ¶
const ( ConfigKey = "config" ErrorKey = "error" HealthStatusKey = "health_status" PanicKey = "panic" StacktraceKey = "stacktrace" TraceIDKey = "trace_id" SpanIDKey = "span_id" SampledKey = "sampled" SubjectKey = "subject" RPCSystemKey = "rpc_system" RPCServiceKey = "rpc_service" RPCMethodKey = "rpc_method" ResourceIDKey = "resource_id" ResourceNameKey = "resource_name" )
Keys to use in log attributes.
Variables ¶
This section is empty.
Functions ¶
func FromContext ¶ added in v0.0.90
FromContext returns the logger from the context, or the default logger if none exists.
func HealthStatus ¶
HealthStatus returns the given value with the "health_status" key.
func IntoContext ¶ added in v0.0.114
IntoContext adds the given logger to the context, returning the new context.
func RPCService ¶
RPCService returns the given value with the "rpc_service" key.
func RPCSystem ¶ added in v0.0.90
RPCSystem returns the given value with the "rpc_system" key. It should be used to capture the protocol a RPC request uses, e.g. gRPC, ConnectRPC, etc.
func Sampled ¶ added in v0.0.123
Sampled returns the sampled status from the given span with the "sampled" key.
func SpanID ¶ added in v0.0.123
TraceID returns the span ID from the given span with the "span_id" key.
func Stacktrace ¶
Stacktrace returns the current stacktrace with the "stacktrace" key. It should primarily be used during panic recovery.
Types ¶
This section is empty.