
Go Logging
Opinionated, standard library first guidance for logging in Go. It pushes slog hard for new code, keeps messages static with structured key-value pairs, and hammers home the "log or return, not both" rule to stop error noise from cascading up the stack. The level semantics are sensible (Error means operator attention, not just "something went wrong"), and the request-scoped logger pattern via context is the right way to carry trace IDs through your handlers. If you're still using log.Printf or debating between zap and zerolog without profiling first, this will save you from yourself.
- skills.sh installs
- 1.1K
- GitHub stars
- 193
- last updated
- Aug 21, 2026
Install
$ npx -y skills add cxuu/golang-skills --skill go-logging --agent claude-codeInstalls into .claude/skills of the current project.
Files
Go Logging
Compatibility:
log/slogrequires Go 1.21+;testing/slogtestrequires 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 fromlog.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/slogfor 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
Sponsors
Details
- Repository
- github.com/cxuu/golang-skills
- Categories
- DevOps & CI/CD, Documentation, Debugging, Go
- First seen
- Jun 3, 2026
More from cxuu/golang-skills
All 20- Go Functions1.1K
- Go Generics1.1K
- Go Declarations1.1K
- Go Code Review1.8K
- Go Testing1.4K
- Go Error Handling1.3K
- Go Linting1.3K
- Go Concurrency1.3K
- Go Interfaces1.3K
- Go Documentation1.3K
- Go Style Core1.3K
- Go Performance1.3K
- Go Context1.3K
- Go Naming1.3K
- Go Defensive1.3K
- Go Packages1.3K
- Go Data Structures1.3K
- Go Functional Options1.3K
- Go Control Flow1.3K