
zap
A fast, structured logging library for Go programs.
- Stars
- 24.7k
- Forks
- 1.6k
- Licence
- MIT
- Language
- Go
- Last update
- 2 months ago
- Type
- Library
What it is
Zap is a logging library for the Go programming language. It writes log messages with levels (such as info or error) and attached key-value details, so logs are easy to search and analyze. Developers use it in server code where logging speed matters, and it offers two APIs: a faster strongly typed one and a looser, more convenient one.
- Log an event with structured fields such as a URL, retry attempt, and backoff duration
- Create a production logger with zap.NewProduction() and write messages through it
- Use the SugaredLogger for printf-style messages in less performance-sensitive code
- Add fixed context fields to a logger once and reuse it across log calls
Great for
- Go developers building services that log heavily
- Teams that want structured, machine-readable log output
- Projects where logging overhead in hot code paths is a concern
- Developers who want a choice between typed and loosely typed logging APIs
Not ideal for
- Non-Go projects, since it is only for Go (reason: it is a Go library)
- Beginners who only need simple print statements (reason: setup and typed fields add concepts to learn)
- Projects that must use only the standard library's log/slog (reason: zap is a separate dependency with its own API)
How to get it
- 1
Install with a package manager
You'll need: Go (the README notes zap supports the two most recent minor versions of Go)
Install zap into a Go module
go get -u go.uber.org/zap - 2
Run it
- Install the package with go get -u go.uber.org/zap
- Create a logger with zap.NewProduction() and defer logger.Sync()
- Call logger.Info with zap.String, zap.Int or similar fields
- Or call logger.Sugar() for the SugaredLogger with Infow or Infof
- 3
Get the most out of it
- Use the typed Logger in hot code paths and the SugaredLogger elsewhere, as the README suggests
- Read the documentation on pkg.go.dev and the project's FAQ.md for details
- Call logger.Sync() before exit so buffered output is flushed
- Pin the dependency to ^1 if you use semver-aware tooling, as the README recommends
Downloads
Strengths
- The README reports strong benchmark results against several other Go logging packages, with the caveat that benchmarks should be taken with a grain of salt
- Offers both a strongly typed Logger and a looser SugaredLogger so you can choose the trade-off
- Stable API with a stated commitment to no breaking changes in the 1.x series
Trade-offs
- Only supports the two most recent minor versions of Go, according to the README
- Typed Logger API requires more verbose code than the SugaredLogger
- Performance claims come from the project's own benchmark suite, so independent results may differ
How it compares
| Project | Stars | Type | Level | Updated | Best for |
|---|---|---|---|---|---|
| zap (this) | 24.7k | Library | beginner | 2 months ago | Go developers building services that log heavily |
| zerolog | 12.5k | Library | beginner | 23 days ago | Go developers who want machine-readable JSON logs |
| logrus | 25.8k | Library | beginner | 1 months ago | Go developers with existing code that already uses Logrus |
| gf | 13.3k | Framework | intermediate | 7 days ago | Go developers looking for a full-featured framework |
| dozzle | 14.8k | App | beginner | 4 days ago | Developers who want to watch container logs while debugging |
| go-zero | 33.4k | Library | intermediate | 5 days ago | Go developers building REST APIs or microservices |
Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.