Zap records structured, leveled log lines in Go programs with an emphasis on low allocation and CPU cost. It offers a strict Logger API and a looser SugaredLogger with printf-style helpers.
Overview
Zap is a logging package for Go that targets hot paths where encoding and formatting would otherwise dominate cost. It ships a reflection-free JSON encoder and a core Logger that avoids unnecessary serialization work and heap churn when fields are already attached.
The SugaredLogger sits on the same core and adds familiar loosely typed and sprintf-style calls when convenience matters more than squeezing allocations. Documentation contrasts when to pick each surface.
Compared with relying on the standard library's formatting and JSON packages for rich structs, the project argues that repeated reflection and small allocations add up in tight loops. Published benchmarks in the project compare Zap against other Go logging stacks on messages with many fields, reused context, and plain static strings.
Installation is via the Go module path go.uber.org/zap, with support limited to the two latest Go minor releases. The maintainers describe the 1.x API as stable for semver pinning.
Key features
- Structured JSON log encoding
- Leveled Logger and SugaredLogger
- Reflection-free encoder path
- Context fields with low overhead
- Printf-style sugared helpers
- Benchmarked against other loggers
- Stable 1.x public API
- Go module distribution
Use cases
- High-throughput service logging
- JSON logs for aggregators
- Performance-sensitive microservices
- Libraries needing typed log fields
- Migrating off fmt-heavy logging