Repolode
rs

rs/zerolog

A zero-allocation JSON logger for Go with a chaining API, leveled and sampled logging, and optional CBOR output.

Stars
12,519
Forks
657
Open issues
166
Last commit
10 days ago

What is it?

Zerolog is a structured logging library for Go that writes events as JSON, or as CBOR when built with a tag. Log events are built through a chaining API that adds strongly typed key-value fields without reflection, which keeps allocations at zero for the common paths in its benchmarks.

The library supports seven levels from trace to panic, global and per-logger level control, log sampling, and hooks that can add fields to every event. Context integration lets a logger be attached to a context.Context and retrieved later, and the hlog package provides helpers for net/http handlers. It also includes a slog.Handler so code using the standard log/slog API can route records through zerolog.

For local development, zerolog.ConsoleWriter turns events into colorized, human-readable lines, though it is slower than the JSON path and is not intended for production. Stack traces for errors are available through the pkgerrors subpackage.

Key features

  • 01Chaining API that writes JSON or CBOR without reflection or allocations on common paths
  • 02Seven leveled logging levels with global level control
  • 03Log sampling, including burst and basic samplers
  • 04Hooks for adding fields to every event
  • 05Integration with context.Context, net/http handlers and log/slog
  • 06ConsoleWriter for colorized local output

Use cases

  • Logging high-throughput Go services where allocation overhead matters
  • Emitting structured JSON logs for ingestion by log aggregation systems
  • Adding request-scoped fields to logs in HTTP servers
  • Bridging existing slog-based code to a JSON backend

Quick start

  1. 1

    Install the module

    go get -u github.com/rs/zerolog/log
  2. 2

    Import the global logger and log a message

Things to know

  • Focused on structured JSON (or CBOR) output; console-friendly output needs the less efficient ConsoleWriter.

In collections

Topics

FAQ

What is zerolog?
A zero-allocation JSON logger for Go with a chaining API, leveled and sampled logging, and optional CBOR output. Zerolog is a structured logging library for Go that writes events as JSON, or as CBOR when built with a tag. Log events are built through a chaining API that adds strongly typed key-value fields without reflection, which keeps allocations at zero for the common paths in its benchmarks.
Is zerolog free to use? What license does it have?
zerolog is open source under the MIT license. Check the license terms before using it in commercial products.
Is zerolog still maintained?
Actively maintained. The last commit to zerolog was on Oct 14, 2026.
What can I use zerolog for?
Logging high-throughput Go services where allocation overhead matters Emitting structured JSON logs for ingestion by log aggregation systems Adding request-scoped fields to logs in HTTP servers Bridging existing slog-based code to a JSON backend
How do I install zerolog?
Install the module: go get -u github.com/rs/zerolog/log Import the global logger and log a message
Where can I get zerolog?
The source code and installation instructions are on GitHub: https://github.com/rs/zerolog

Summary generated by AI from the project's README. GitHub stats refresh daily.

Related projects