$npx -y skills add samber/cc-skills-golang --skill golang-samber-slogStructured logging extensions for Golang using samber/slog-**** packages — multi-handler pipelines (slog-multi), log sampling (slog-sampling), attribute formatting (slog-formatter), HTTP middleware (slog-fiber, slog-gin, slog-chi, slog-echo), and backend routing (slog-datadog, sl
| 1 | **Persona:** You are a Go logging architect. You design log pipelines where every record flows through the right handlers — sampling drops noise early, formatters strip PII before records leave the process, and routers send errors to Sentry while info goes to Loki. |
| 2 | |
| 3 | # samber/slog-\*\*\*\* — Structured Logging Pipeline for Go |
| 4 | |
| 5 | 20+ composable `slog.Handler` packages for Go 1.21+. Three core pipeline libraries plus HTTP middlewares and backend sinks that all implement the standard `slog.Handler` interface. |
| 6 | |
| 7 | **Official resources:** |
| 8 | |
| 9 | - [github.com/samber/slog-multi](https://github.com/samber/slog-multi) — handler composition |
| 10 | - [github.com/samber/slog-sampling](https://github.com/samber/slog-sampling) — throughput control |
| 11 | - [github.com/samber/slog-formatter](https://github.com/samber/slog-formatter) — attribute transformation |
| 12 | |
| 13 | This skill is not exhaustive. Please refer to library documentation and code examples for more information. For Go package docs, symbols, versions, importers, and known vulnerabilities, → See `samber/cc-skills-golang@golang-pkg-go-dev` skill (`godig`) — prefer it over Context7 for Go package facts. To navigate this library's usage in your own code (definitions, call sites, diagnostics), → See `samber/cc-skills-golang@golang-gopls` skill (`gopls`). Context7 remains a fallback for docs not indexed on pkg.go.dev. |
| 14 | |
| 15 | ## The Pipeline Model |
| 16 | |
| 17 | Every samber/slog pipeline follows a canonical ordering. Records flow left to right — place sampling first to drop early and avoid wasting CPU on records that never reach a sink. |
| 18 | |
| 19 | ``` |
| 20 | record → [Sampling] → [Pipe: trace/PII] → [Router] → [Sinks] |
| 21 | ``` |
| 22 | |
| 23 | Order matters: sampling before formatting saves CPU. Formatting before routing ensures all sinks receive clean attributes. Reversing this wastes work on records that get dropped. |
| 24 | |
| 25 | ## Core Libraries |
| 26 | |
| 27 | | Library | Purpose | Key constructors | |
| 28 | | --- | --- | --- | |
| 29 | | `slog-multi` | Handler composition | `Fanout`, `Router`, `FirstMatch`, `Failover`, `Pool`, `Pipe` | |
| 30 | | `slog-sampling` | Throughput control | `UniformSamplingOption`, `ThresholdSamplingOption`, `AbsoluteSamplingOption`, `CustomSamplingOption` | |
| 31 | | `slog-formatter` | Attribute transforms | `PIIFormatter`, `ErrorFormatter`, `FormatByType[T]`, `FormatByKey`, `FlattenFormatterMiddleware` | |
| 32 | |
| 33 | ## slog-multi — Handler Composition |
| 34 | |
| 35 | Six composition patterns, each for a different routing need: |
| 36 | |
| 37 | | Pattern | Behavior | Latency impact | |
| 38 | | --- | --- | --- | |
| 39 | | `Fanout(handlers...)` | Broadcast to all handlers sequentially | Sum of all handler latencies | |
| 40 | | `Router().Add(h, predicate).Handler()` | Route to ALL matching handlers | Sum of matching handlers | |
| 41 | | `Router().Add(...).FirstMatch().Handler()` | Route to FIRST match only | Single handler latency | |
| 42 | | `Failover()(handlers...)` | Try sequentially until one succeeds | Primary handler latency (happy path) | |
| 43 | | `Pool()(handlers...)` | Load-balance: sends each record to ONE handler | Single handler latency | |
| 44 | | `Pipe(middlewares...).Handler(sink)` | Middleware chain before sink | Middleware overhead + sink | |