Advanced Go Structured Logging (samber/slog)

0•

Architects and implements high-performance, structured logging pipelines for Go using the samber/slog ecosystem.

This skill provides comprehensive guidance for building sophisticated logging infrastructures in Go 1.21+ using the popular samber/slog library suite. It assists developers in configuring multi-handler pipelines, implementing intelligent log sampling to control costs, applying attribute formatters for PII scrubbing, and integrating with diverse backend sinks like Datadog, Sentry, and Loki. It ensures best practices are followed, such as the canonical pipeline ordering and graceful shutdown of batch handlers, to prevent data loss and performance bottlenecks.

Key Features

01Pre-built HTTP middleware for Gin, Echo, Fiber, Chi, and net/http
020 GitHub stars
03Composable handler pipelines with Fanout, Router, Failover, and Pool patterns
04Automated attribute formatting, PII scrubbing, and error structuring
05Integration with 20+ backend sinks including Datadog, Sentry, Loki, and Kafka
06Intelligent log sampling strategies including Uniform, Threshold, and Absolute

Use Cases

01Building production-grade pipelines that route errors to Sentry and info logs to Loki
02Implementing PII masking and log sampling to reduce storage costs and meet compliance
03Adding structured request logging with trace propagation to Go web applications