golang-samber-slog

Compose structured logging pipelines in Go using samber/slog handler libraries.

1|Updated Jun 2, 2026
One-click install
npx skills add https://github.com/VerifiedOrganic/onboard --skill golang-samber-slog-verifiedorganic
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: golang-samber-slog
Source: https://github.com/VerifiedOrganic/onboard/tree/main/.agents/skills/golang-samber-slog
Command: npx skills add https://github.com/VerifiedOrganic/onboard --skill golang-samber-slog-verifiedorganic

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Building production logging in Go with slog requires wiring together sampling, PII scrubbing, routing, and backend sinks, and mistakes like sampling after formatting or forgetting to flush batch handlers silently waste CPU or lose logs. ## Core Features & Use Cases - Pipeline Composition: Combine slog-multi patterns (Fanout, Router, FirstMatch, Failover, Pool, Pipe) to route records by level, message, or attribute to the right destinations. - Throughput Control: Apply slog-sampling strategies (Uniform, Threshold, Absolute, Custom) with matchers that deduplicate repeated messages while preserving error visibility. - Backend Integration: Connect 20+ sinks including Datadog, Sentry, Loki, Kafka, Slack, and Parquet, plus HTTP middlewares for Gin, Echo, Fiber, Chi, and net/http. - Use Case: Route ERROR logs to Sentry unsampled while sampling INFO logs at 10% to Loki, with PII scrubbed before any record leaves the process. ## Quick Start Ask the agent to set up a slog pipeline that samples info logs, scrubs PII, and routes errors to Sentry with the rest going to Loki.

Frequently Asked Questions about golang-samber-slog

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

FAQPage Schema
How do I set up log sampling with samber/slog-sampling in Go?▼

Use ThresholdSamplingOption with a Tick, Threshold, and Rate, then wrap it as a Pipe middleware via NewMiddleware(). Place sampling as the outermost handler so dropped records never waste CPU on formatting.

How do I route ERROR logs to Sentry and everything else to Loki with slog-multi?▼

Use slogmulti.Router() with Add(sentryHandler, slogmulti.LevelIs(slog.LevelError)) and a catch-all Loki handler, then call FirstMatch() so errors stop at the first matching route and skip sampling.

What is the difference between slog-multi Fanout, Router, and Pool?▼

Fanout broadcasts every record to all handlers sequentially with latency equal to their sum. Router sends records to handlers matching predicates, while Pool load-balances each record to one handler with latency of a single handler.

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 and drop them on exit. Call handler.Stop(ctx), lokiClient.Stop(), writer.Close(), or buffer.Flush(true) during graceful shutdown.

Does slog-gin support different log levels for 4xx and 5xx responses?▼

Yes, sloggin.NewWithConfig accepts a Config struct with DefaultLevel, ClientErrorLevel, and ServerErrorLevel fields. Set ClientErrorLevel to Warn and ServerErrorLevel to Error without writing custom middleware.

Why is AttrFromContext returning empty request IDs in my logs?▼

AttrFromContext only reads values already present in the context, so without an HTTP middleware like slog-gin or slog-chi populating them, it silently returns nil. Install the middleware with WithRequestID enabled first.