samber-slog

Design structured logging pipelines in Go using samber/slog handler composition, sampling, and routing.

1|2|Updated Nov 25, 2017
One-click install
npx skills add https://github.com/asarchami/dotfiles --skill samber-slog-asarchami
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: samber-slog
Source: https://github.com/asarchami/dotfiles/tree/main/dot_config/opencode/skills/samber/samber-slog
Command: npx skills add https://github.com/asarchami/dotfiles --skill samber-slog-asarchami

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Go services generating high log volumes need structured pipelines that sample noise, scrub PII, and route records to the right backends without wasting CPU or losing buffered logs on shutdown. This Skill provides the canonical ordering and composition patterns for building such pipelines with the samber/slog-* ecosystem. ## Core Features & Use Cases - Pipeline composition: Combine Fanout, Router, FirstMatch, Failover, Pool, and Pipe handlers from slog-multi with correct ordering (sampling → formatting → routing → sinks). - Sampling and formatting: Apply Uniform, Threshold, Absolute, or Custom sampling strategies plus PII, error, and IP address formatters as middleware. - Backend sinks and middleware: Ship logs to Datadog, Sentry, Loki, Kafka, Slack, and more, with HTTP middleware for Gin, Echo, Fiber, Chi, and net/http. - Use Case: Route error logs to Sentry unsampled while sending sampled info logs to Loki, with PII scrubbed before any sink receives records. ## Quick Start Design a Go slog pipeline that routes errors to Sentry and sampled info logs to Loki with PII formatting applied first.

Frequently Asked Questions about samber-slog

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I route Go slog records to different backends by level?

Use slogmulti.Router with predicates like LevelIs to send errors to Sentry and info logs to Loki. Always add a predicate-less catch-all handler so unmatched records are not silently dropped.

What is the correct order for a samber slog pipeline?

Order the pipeline as sampling, then formatting, then routing, then sinks. Sampling first avoids wasting CPU formatting records that get dropped, and formatting before routing ensures every sink receives clean attributes.

Fanout vs Pool in slog-multi: which should I use?

Fanout broadcasts sequentially so latency equals the sum of all handler latencies, while Pool dispatches concurrently so latency equals the slowest handler. Use Pool for multiple slow sinks and Fanout only when sequential delivery is acceptable.

Why are my buffered logs lost when my Go service shuts down?

Batch handlers like slog-datadog, slog-loki, slog-kafka, and slog-parquet buffer records internally. You must call Stop, Close, or Flush on shutdown via defer, or pending buffered logs are discarded.

Why does AttrFromContext return nil in my slog handlers?

AttrFromContext only works when an HTTP middleware such as slog-gin, slog-echo, slog-fiber, or slog-chi has populated the request context first. Install the framework middleware with router.Use before any handler reads context attributes.

How do I sample logs without dropping errors in Go slog?

Combine a FirstMatch Router with sampling: add the error handler as the first route without sampling, then route everything else through a sampling middleware. Threshold sampling preserves the first N records per interval before rate-based sampling.