
zerolog
A fast Go logging library that writes structured JSON with almost no memory allocation.
- Stars
- 12.5k
- Forks
- 661
- Licence
- MIT
- Language
- Go
- Last update
- 23 days ago
- Type
- Library
What it is
Zerolog is a logging library for the Go programming language. It records events as structured JSON (or optionally CBOR), where each message can carry typed key-value fields such as strings, numbers, and errors. It is built to avoid allocations and reflection, which the README says keeps it fast and light on memory.
- Logging HTTP request details as structured fields
- Attaching contextual data such as user IDs to each log event
- Logging errors with optional stack traces using the pkgerrors package
- Filtering output by level (trace through panic) or turning logging off
- Using log sampling and hooks to control which events get written
Great for
- Go developers who want machine-readable JSON logs
- Backend services where logging overhead matters
- Teams that log structured fields and send logs to log-processing tools
- Developers who want a chained, typed logging API
Not ideal for
- People who want readable colored console output by default: the README says pretty printing via ConsoleWriter is available but inefficient
- Non-Go projects, since it is a Go package
- Beginners who need a full logging framework with rotation or file management, which the README does not describe
How to get it
- 1
Install with a package manager
You'll need: Go
Install the global logger package
go get -u github.com/rs/zerolog/log - 2
Run it
- Install the package with go get as shown in the README
- Create a main.go file that imports github.com/rs/zerolog/log
- Call log.Print("hello world") or log.Info().Msg("hello world") inside main
- Run the program and read the JSON line written to stderr
- 3
Get the most out of it
- Set zerolog.TimeFieldFormat to zerolog.TimeFormatUnix for smaller timestamps, as the README suggests
- Call zerolog.SetGlobalLevel to hide trace and debug output in production
- Use zerolog.ConsoleWriter during development for readable output
- Use the pkgerrors package with zerolog.ErrorStackMarshaler to add stack traces to errors
- Use the context.Context and net/http integrations listed in the README
Downloads
Strengths
- Designed for low or zero allocation, per the README benchmarks section
- Strongly typed fields and a simple chaining API
- Supports leveled logging, sampling, hooks, and log/slog integration
Trade-offs
- Chained calls silently do nothing unless Msg or Msgf is called, and the compiler will not warn you
- By default it writes every level, including trace, to stderr until SetGlobalLevel is called
- Pretty console output is available but slower, as the README notes
How it compares
| Project | Stars | Type | Level | Updated | Best for |
|---|---|---|---|---|---|
| zerolog (this) | 12.5k | Library | beginner | 23 days ago | Go developers who want machine-readable JSON logs |
| zap | 24.7k | Library | beginner | 2 months ago | Go developers building services that log heavily |
| logrus | 25.8k | Library | beginner | 1 months ago | Go developers with existing code that already uses Logrus |
| gjson | 15.6k | Library | beginner | 1 months ago | Go developers who need a few fields from a JSON response without writing struct definitions |
| go | 13.9k | Library | beginner | 2.4 years ago | Go developers who parse or produce large amounts of JSON and want to test a faster option |
| gf | 13.3k | Framework | intermediate | 7 days ago | Go developers looking for a full-featured framework |
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.