golang-samber-slog

Design Go structured logging pipelines with samber/slog for routing and delivery.

2|Updated Mar 13, 2023
One-click install
npx skills add https://github.com/haipham22/golang-sample --skill golang-samber-slog-haipham22
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-samber-slog
Source: https://github.com/haipham22/golang-sample/tree/main/.agents/skills/golang-samber-slog
Command: npx skills add https://github.com/haipham22/golang-sample --skill golang-samber-slog-haipham22

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps you design production-ready structured logging pipelines in Go with samber/slog, so logs are routed, sampled, formatted, and shipped correctly without wasted CPU or missed shutdown flushes.

Core Features & Use Cases

  • Pipeline composition: Combine sampling, formatting, routing, and sink handlers with slog-multi.
  • Noise control and PII safety: Sample early, scrub sensitive fields, and keep downstream handlers clean.
  • HTTP middleware integration: Configure slog-gin, slog-echo, slog-fiber, slog-chi, or slog-http for request logging and request-scoped attributes.
  • Backend delivery: Send logs to Sentry, Loki, Datadog, Kafka, Slack, Telegram, Webhook, Parquet, or bridge to Zap, Zerolog, and Logrus.
  • Use case: A Go API can log 4xx and 5xx at different severities, route errors to alerts, keep info logs in observability storage, and flush buffered sinks during graceful shutdown.

Quick Start

Use this skill to design a Go logging setup that samples noisy records first, scrubs PII, routes errors to the right backend, and closes buffered handlers safely.

Frequently Asked Questions about golang-samber-slog

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

FAQPage Schema
How do I build a structured logging pipeline in Go using slog?

To build a structured logging pipeline in Go using slog, combine sampling, formatting, routing, and sink handlers via slog-multi. This ensures logs are routed by severity, sampled for noise control, and safely flushed during graceful shutdown.

How does slog handler composition work for PII scrubbing and log routing?

slog handler composition chains multiple handlers so you can sample noisy records first, scrub sensitive PII fields, and then route logs by severity to different backends like Sentry or Loki, keeping downstream handlers clean and efficient.

Can I integrate slog HTTP middleware with frameworks like Gin, Echo, or Fiber?

Yes, you can integrate slog HTTP middleware with Gin, Echo, Fiber, Chi, or standard net/http. These integrations provide request logging and automatically attach request-scoped attributes to your structured logs.

What is the best way to route Go application logs to Datadog, Loki, and Sentry?

The best way to route Go application logs to Datadog, Loki, and Sentry is using samber/slog with slog-multi to route records by severity. Errors go to alerting backends, while info logs go to observability storage.

Why do my buffered slog handlers lose logs when the Go server shuts down?

Buffered slog handlers lose logs during server shutdown because they require a graceful shutdown process to flush pending records. You must explicitly close the handlers to ensure all buffered logs are delivered to their backends before exit.

Does slog support bridging logs from existing Zap or Zerolog implementations?

Yes, slog supports bridging logs from existing Zap, Zerolog, and Logrus implementations. This allows you to migrate to a unified structured logging pipeline without rewriting all existing logging calls immediately.