explaingit

rs/zerolog

12,379GoAudience · developerComplexity · 2/5LicenseSetup · easy

TLDR

A Go logging library that writes structured JSON log entries using zero memory allocations, making it ideal for high-traffic services where logging speed matters.

Mindmap

mindmap
  root((zerolog))
    Core design
      Zero allocations
      JSON output
      Method chaining
    Log levels
      Trace and Debug
      Info and Warn
      Error Fatal Panic
    Features
      Console writer
      Sampling
      Hooks
      Stack traces
    Integrations
      context package
      net/http
      log/slog interface
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Add fast, structured JSON logging to a Go web service with minimal impact on request throughput.

USE CASE 2

Attach typed fields like user IDs, status codes, and durations to each log entry for easy filtering in log tools.

USE CASE 3

Use the colored console output mode during local development for human-readable logs, then switch to JSON in production.

USE CASE 4

Integrate zerolog as the backend for code already written against Go's standard log/slog interface.

Tech stack

Go

Getting it running

Difficulty · easy Time to first run · 5min
MIT license, use freely in any project, including commercial, as long as you keep the copyright notice.

In plain English

Zerolog is a Go logging library designed for speed and low overhead. Its main claim is that it produces zero memory allocations when writing log entries, which matters for high-throughput services where even small per-request costs add up. Log output is structured JSON by default, meaning each log line is a machine-readable object rather than a free-form string. The API uses method chaining: you call something like log.Info().Str("user", userId).Int("status", 200).Msg("request complete") and zerolog builds the JSON object and writes it in one pass. The chained calls let you attach any number of typed fields (strings, integers, floats, booleans, errors, durations) to each log entry, which makes logs easier to search and filter in log aggregation tools. Log levels go from trace and debug at the low end up through info, warn, error, fatal, and panic. For development, zerolog includes a ConsoleWriter that formats output as readable colored text instead of JSON. The README explicitly notes this mode is slower and not intended for production. The library also supports sampling (writing only a fraction of log messages at a given level to reduce volume), hooks for custom processing on each log event, and optional stack traces on errors via the pkg/errors integration. Integration hooks exist for Go's standard library context package (to carry a logger through request chains) and for the standard net/http package. Zerolog also integrates with the log/slog interface introduced in Go 1.21, so you can swap in zerolog as the backend for code written against the standard interface. Install via go get. The project is MIT-licensed and maintains benchmarks comparing its performance against other Go loggers.

Copy-paste prompts

Prompt 1
Show me how to set up zerolog in a Go HTTP handler so every request logs the method, path, status code, and duration as a single JSON line with zero allocations.
Prompt 2
I want to carry a zerolog logger through a chain of Go functions via context. Show me the setup using zerolog's context integration.
Prompt 3
How do I configure zerolog to sample log messages, for example, only write 1 in 10 debug-level entries, to reduce log volume in production?
Prompt 4
Walk me through wiring zerolog up as the backend for Go's standard slog interface so I can drop it into existing code without changing call sites.
Open on GitHub → Explain another repo

← rs on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.