Zap
pkg.go.dev
1
Leaving SiteNav
External Link Disclaimer
You are about to visit pkg.go.dev. This website is not operated by us. We are not responsible for its content or privacy practices.
About this website
Zap is a high-performance, zero-allocation logging library for Go, developed and maintained by Uber Technologies. It was created to address the performance limitations of existing Go logging libraries, which often generate significant garbage collection pressure and CPU overhead in high-throughput production systems. In Uber's own benchmarks, Zap outperforms the standard library log package by over 40x and other structured logging libraries like Logrus by more than 10x in scenarios requiring structured output, while using significantly less memory. The library provides two primary API styles: the SugaredLogger (a ergonomic, developer-friendly API that uses reflection and interface{} parameters, suitable for development and less performance-critical code paths) and the Logger (a strongly-typed, zero-allocation API that requires explicit field typing, recommended for hot code paths where every allocation matters). Key features include: structured logging with strongly typed fields (zap.String, zap.Int, zap.Duration, zap.Error, and more), zero-allocation logging in the Logger API by avoiding interface boxing and reflection, configurable log levels (Debug, Info, Warn, Error, DPanic, Panic, Fatal), pluggable encoders supporting both JSON and console (human-readable) output formats, highly configurable output destinations via WriteSyncer (files, stdout, network, or any io.Writer), sampling for high-frequency log messages (e.g., only logging the first N messages per second at a given level to prevent log flooding), automatic stack trace collection for error and higher severity logs, custom field hooks and core wrapping for extending behavior, and integration with the standard library log package via zap.NewStdLog. As of 2026, Zap has over 22,000 GitHub stars.
Tags & Categories
Categories
Tags
Statistics
1
Views
0
Clicks
0
Like
0
Dislike