Getting started

Overview

zerolog is a zero-allocation JSON logging library for Go — what it is, how to install it, and where its packages live.

zerolog

zerolog provides a fast and simple logger dedicated to JSON output for Go. It is designed around the idea that structured logging should not cost allocations: the library uses a lock-free, zero-allocation JSON encoder, which makes it one of the fastest logging options in the Go ecosystem while keeping a familiar, chainable API.

Why zerolog

The library's promise is stated by its benchmark suite: zerolog's JSON encoder is faster than the standard library's encoding/json and most structured loggers because it builds events in a reusable byte buffer instead of allocating intermediate maps. Log levels (trace, debug, info, warn, error, fatal, panic, and no level), contextual sub-loggers, error events with stack traces, sampling, and hooks are all part of the core. Binary encoding via CBOR is available through internal/cbor-backed helpers for consumers that need compact output.

Install

go get github.com/rs/zerolog/log

The module has no external dependencies. Import the log subpackage for the global logger, or use the root zerolog package directly when you manage your own Logger instances.

Quick start

package main

import (
    "github.com/rs/zerolog"
    "github.com/rs/zerolog/log"
)

func main() {
    zerolog.TimeFieldFormat = zerolog.TimeFormatUnix

    log.Debug().
        Int("port", 8080).
        Msg("server starting")
}

The chainable event API means every typed field call (Str, Int, Err, Dict, Array, ...) mutates the current event and returns it, so building rich structured entries reads top-to-bottom without allocations.

Where to go next

The Go API reference documents all 13 packages of the module, including the root zerolog package (events, contexts, writers, sampling), the log global logger, hlog HTTP helpers, diode lock-free ring buffers for concurrent writers, journald systemd integration, and pkgerrors stack-trace marshalling. Every entry carries its source signature and, where present, example code extracted from the module's own *_test.go files.

About this site

This documentation is a Sourcey-generated mirror of the github.com/rs/zerolog module's godoc, built from the module source at a pinned commit. It exists to make zerolog's full API surface browsable, searchable, and agent-readable (llms.txt) in one static site.

Edit this page

Sourcey-generated documentation mirror for rs/zerolog (MIT), built from source at a pinned commit.Docs by Sourcey