golang-samber-slog

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

Updated May 9, 2026
One-click install
npx skills add https://github.com/LuminaVault/LuminaVaultShared --skill golang-samber-slog-luminavault
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: golang-samber-slog
Source: https://github.com/LuminaVault/LuminaVaultShared/tree/main/.agents/skills/golang-samber-slog
Command: npx skills add https://github.com/LuminaVault/LuminaVaultShared --skill golang-samber-slog-luminavault

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Building production-grade structured logging in Go 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. This Skill provides the canonical pipeline patterns and correct constructor usage for the 20+ samber/slog-* handler packages. ## Core Features & Use Cases - Pipeline composition: Combine slog-multi patterns (Fanout, Router, FirstMatch, Failover, Pool, Pipe) with slog-sampling and slog-formatter in the correct ordering. - HTTP middleware setup: Configure slog-gin, slog-echo, slog-fiber, slog-chi, or slog-http with per-status-code log levels and request filters. - Backend sinks and shutdown: Wire Datadog, Sentry, Loki, Kafka, Slack, and other sinks with the Option{}.NewXxxHandler() pattern and required graceful-shutdown flushes. - Use Case: Route ERROR logs to Sentry unsampled while sampling INFO logs at 10% into Loki, with PII scrubbed before any record leaves the process. ## Quick Start Set up a slog pipeline in Go using samber/slog libraries that samples info logs at 10%, scrubs PII, and routes errors to Sentry with graceful shutdown.

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 apply it as a Pipe middleware via NewMiddleware(). Place sampling as the outermost handler so dropped records never waste CPU on formatting or routing.

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

Use slogmulti.Router() with Add(sentryHandler, slogmulti.LevelIs(slog.LevelError)) and a catch-all Loki handler. Add FirstMatch() if error records should not also flow through the sampled Loki path.

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

Fanout broadcasts every record to all handlers sequentially with latency equal to their sum. Pool load-balances each record to one handler, and Router dispatches to all handlers whose predicate matches, or only the first match with FirstMatch().

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 must be flushed on shutdown. Call handler.Stop(ctx) for Datadog, lokiClient.Stop() for Loki, writer.Close() for Kafka, or buffer.Flush(true) for Parquet.

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 slog.LevelWarn and ServerErrorLevel to slog.LevelError without writing custom middleware.

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

AttrFromContext only works when an HTTP middleware such as slog-gin, slog-echo, slog-fiber, or slog-chi has populated the context first. Install the middleware with WithRequestID enabled so request attributes exist for handlers to extract.