golang-samber-slog

Create Go slog pipelines with sampling, formatting, and multi-backend routing.

2|Updated Feb 12, 2024
One-click install
npx skills add https://github.com/adibfirman/dotfiles --skill golang-samber-slog-adibfirman
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-samber-slog
Source: https://github.com/adibfirman/dotfiles/tree/main/claude/.claude/skills/technical/golang/golang-samber-slog
Command: npx skills add https://github.com/adibfirman/dotfiles --skill golang-samber-slog-adibfirman

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps you design structured Go logging pipelines using samber/slog-* packages so records flow through the right handlers (sampling, formatting, routing, and sinks) with minimal wasted CPU and correct error visibility.

Core Features & Use Cases

  • Sampling-first pipeline: Drops noise early to reduce cost by placing slog-sampling as the outermost stage.
  • PII-safe attribute formatting: Uses slog-formatter middleware to transform or redact attributes (e.g., PII and IP address fields) before emission.
  • Composed routing to multiple backends: Uses slog-multi (Router/Fanout/Pipe patterns) to route records and selectively deliver error traffic to sinks like Sentry while routing others to Loki or stdout.
  • HTTP middleware integration: Applies framework-specific HTTP middlewares (Gin/Chi/Fiber/FastHTTP/etc.) so request context attributes can be extracted via AttrFromContext by backend handlers.
  • Backend sink readiness: Provides practical guidance for configuring and safely shutting down batch-oriented sinks (e.g., Loki/Datadog/Kafka/Parquet) to avoid losing buffered logs.

Quick Start

Use the golang-samber-slog skill to generate a Go slog pipeline that samples first, scrubs email/IP fields via slog-formatter, routes errors to Sentry and the rest to Loki using slog-multi Router, and includes the required handler shutdown/flush steps for buffered sinks.

Frequently Asked Questions about golang-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 general logs to Loki?

Use slog-multi Router or FirstMatch patterns to route Go slog records to multiple backends, sending error traffic to Sentry and the rest to Loki. Formatter middleware must be applied before routing to ensure records are transformed correctly for each sink.

How do I redact PII fields in Go slog structured logs?

Redact PII in Go slog by inserting slog-formatter middleware into the pipeline before records reach any sink. This transforms or scrubs attributes such as email and IP address fields so sensitive data is never emitted to backends.

What is the best way to reduce log volume in Go slog pipelines?

Reduce log volume by placing slog-sampling as the outermost handler in your Go slog pipeline. This drops noisy records early, minimizing wasted CPU and storage costs before formatting or routing logic is applied.

How do I pass HTTP request context into Go slog handlers?

Integrate framework-specific HTTP middleware for Gin, Chi, or Fiber to extract request context attributes. Backend handlers then use AttrFromContext to enrich Go slog records with request-specific data automatically.

How do I safely shut down batch sinks in Go slog without losing logs?

Safely shut down batch-oriented Go slog sinks like Loki or Datadog by implementing required handler flush steps during service shutdown. This prevents buffered records from being dropped when the pipeline stops.

Why are my Go slog records duplicated when routing to multiple sinks?

Duplicated Go slog records occur when routing logic is misconfigured. Use slog-multi Router with FirstMatch patterns to ensure records match intended conditions and reach only the correct handlers, preventing duplicate or dropped events.