go-samber-slog

Build composable Go slog pipelines with sampling, formatting, routing, and backend sinks.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Go's standard slog package provides a single handler, but production services need log sampling to control volume, PII scrubbing before records leave the process, routing errors to Sentry while info goes to Loki, and graceful flushing of batched sinks. This Skill provides the patterns and APIs to assemble those pipelines correctly using the samber/slog-* ecosystem. ## Core Features & Use Cases - Handler Composition: Combine handlers with slog-multi patterns (Fanout, Router, FirstMatch, Failover, Pool, Pipe) to route records by level, message, or attribute. - Throughput Control: Apply slog-sampling strategies (Uniform, Threshold, Absolute, Custom) to drop noise early while preserving error visibility. - Attribute Transformation & Sinks: Scrub PII with slog-formatter middleware, add HTTP middleware for Gin/Echo/Fiber/Chi, and ship logs to Datadog, Sentry, Loki, Kafka, Slack, and 15+ other backends. - Use Case: Route errors to Sentry unsampled while sending sampled info logs to Loki, with PII masked and trace IDs injected — all in one pipeline with proper shutdown flushing. ## Quick Start Set up a Go slog pipeline that routes error logs to Sentry and sampled info logs to Loki with PII scrubbing using the samber slog-multi, slog-sampling, and slog-formatter packages.

Frequently Asked Questions about go-samber-slog

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

FAQPage Schema
How do I route Go slog errors to Sentry and info logs to Loki?

Use slogmulti.Router() with predicates: add the Sentry handler with slogmulti.LevelIs(slog.LevelError) and the Loki handler for other levels. Add FirstMatch() so errors don't fall through to the sampled path, and always include a catch-all handler to avoid silently dropping records.

How do I sample high-volume Go logs without losing errors?

Use slog-sampling's ThresholdSamplingOption to log the first N records per interval, then sample at a rate. Place sampling as the outermost pipeline stage, and use a FirstMatch router so Warn/Error records bypass sampling entirely and always reach their sink.

Does samber slog support Gin, Echo, Fiber, and Chi middleware?

Yes, dedicated packages exist: slog-gin, slog-echo, slog-fiber, slog-chi, plus slog-http for net/http. All share a Config struct with level mapping, body capture, trace ID options, and filters like IgnorePath and IgnoreStatus.

Why are my Go logs lost when the application shuts down?

Batch handlers like slog-datadog, slog-loki, slog-kafka, and slog-parquet buffer records internally. You must call their shutdown methods (handler.Stop(ctx), lokiClient.Stop(), writer.Close(), buffer.Flush(true)) on exit or buffered logs are discarded.

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

Fanout sends every record to all handlers sequentially (latency is the sum of all handlers). Router sends records only to handlers whose predicates match. Pool distributes each record to one handler for load balancing, keeping latency at a single handler's cost.

How do I mask PII in Go slog output before it reaches backends?

Apply slog-formatter as a Pipe middleware with PIIFormatter and IPAddressFormatter so all downstream handlers receive clean attributes. Place formatting after sampling but before routing so dropped records don't waste formatting CPU.