{"repo":"veqryn/slog-context","free":true,"listed":false,"github":"https://github.com/veqryn/slog-context","clone":"git clone https://github.com/veqryn/slog-context.git","description":"Use golang structured logging (slog) with context. Add and retrieve logger to and from context. Add attributes to context. Automatically read any custom context values, such as OpenTelemetry TraceID.","language":"Go","stars":194,"topics":["context","golang","golang-library","logging","slog","structured-logging","opentelemetry"],"license":"MIT","category":"analytics","readme_excerpt":"slog-context Use golang structured logging (slog) with context. Add and retrieve logger to and from context. Add attributes to context. Automatically read any custom context values, such as OpenTelemetry TraceID. This library supports two different workflows for using slog and context. These workflows can be used individually or together at the same time. Attributes Extracted from Context Workflow: Using the Handler lets us Prepend and Append attributes to log lines, even when a logger is not passed into a function or in code we don't control. This is done without storing the logger in the context; instead the attributes are stored in the context and the Handler picks them up later whenever a new log line is written. In that same workflow, the HandlerOptions and AttrExtractor types let us extract any custom values from a context and have them automatically be prepended or appended to all log lines using that context. By default, there are extractors for anything added via Prepend and Append , but this repository contains some optional Extractors that can be added: slogotel.ExtractTraceSpanID extractor will automatically extract the OTEL (OpenTelemetry) TraceID and SpanID, and add them to the log record, while also annotating the Span with an error code if the log is at error level. sloghttp.ExtractAttrCollection extractor will automatically add to the log record any attributes added by sloghttp.With after the sloghttp.AttrCollection http middleware. This allows other middlewa","default_branch":null,"files":null,"tree":[],"storefront":"/r/veqryn","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/veqryn/slog-context/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}