Skip to content

Structured Go logging guide for slog, log levels, request-scoped context, and what to keep out of logs.

CCM score
65 of 100
skills.sh installs
1.2K
GitHub stars
197
last updated
Aug 21, 2026
View on GitHub

Own this skill? Claim it

What it does

  • Covers logger selection, structured key-value logging, log levels, request-scoped loggers, and sensitive-data exclusions
  • Includes references/LEVELS-AND-CONTEXT.md for level choice and context handling, and references/LOGGING-PATTERNS.md for handler setup, HTTP request logs, testing, and log migration
  • Enforces key-value attributes over interpolated messages, snake_case keys, and no secrets, PII, or unbounded data in logs
  • Designed for Go 1.21+ services that need production logging, and defers error-handling strategy to go-error-handling

Install

$ npx -y skills add cxuu/golang-skills --skill go-logging -y

Installs into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.

Files

Go Logging

Compatibility: log/slog requires Go 1.21+; testing/slogtest requires Go 1.22+.

Resource Routing

  • references/LEVELS-AND-CONTEXT.md - Read when choosing log levels, deciding logger-in-context versus explicit parameters, or excluding sensitive fields.
  • references/LOGGING-PATTERNS.md - Read when configuring slog handlers, logging HTTP requests, testing handlers, or migrating from log.Printf.

Core Principle

Logs are for operators, not developers. Every log line should help someone diagnose a production issue. If it doesn't serve that purpose, it's noise.


Choosing a Logger

Normative: Use log/slog for new Go code.

slog is structured, leveled, and in the standard library (Go 1.21+). It covers the vast majority of production logging needs.

Which logger?
├─ New production code      → log/slog
├─ Trivial CLI / one-off    → log (standard)
└─ Measured perf bottleneck → zerolog or zap (benchmark first)

Do not introduce a third-party logging library unless profiling shows slog is a bottleneck in your hot path. When you do, keep the same structured key-value style.


Structured Logging

Details

Repository
github.com/cxuu/golang-skills
Categories
Go, Backend & APIs, Debugging
First seen
Jun 3, 2026

More from cxuu/golang-skills

All 20

Similar to Go Logging

More Go