Skip to content

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
Step-by-step guide: how to use zerologInstall, first run, examples, tips and FAQs

How to get it

  1. 1

    Install with a package manager

    You'll need: Go

    Install the global logger package

    go get -u github.com/rs/zerolog/log
  2. 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. 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

ProjectStarsTypeLevelUpdatedBest for
zerolog (this)12.5kLibrarybeginner23 days agoGo developers who want machine-readable JSON logs
zap24.7kLibrarybeginner2 months agoGo developers building services that log heavily
logrus25.8kLibrarybeginner1 months agoGo developers with existing code that already uses Logrus
gjson15.6kLibrarybeginner1 months agoGo developers who need a few fields from a JSON response without writing struct definitions
go13.9kLibrarybeginner2.4 years agoGo developers who parse or produce large amounts of JSON and want to test a faster option
gf13.3kFrameworkintermediate7 days agoGo 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.