DEV.co
Open-Source Observability · rs

zerolog

Zerolog is a fast, zero-allocation JSON logging library for Go that outputs structured logs in JSON format. It emphasizes performance through a chaining API that avoids reflection and memory allocations, making it suitable for high-throughput production systems.

Source: GitHub — github.com/rs/zerolog
12.5k
GitHub stars
628
Forks
Go
Primary language
MIT
License (OSI-approved)

Key facts

Objective fields from the source. Values we can't verify are shown as “Unknown” rather than guessed.

FieldValue
Repositoryrs/zerolog
Ownerrs
Primary languageGo
LicenseMIT — OSI-approved
Stars12.5k
Forks628
Open issues145
Latest releaseUnknown
Last updated2026-06-29
Sourcehttps://github.com/rs/zerolog

What zerolog is

Zerolog provides a type-safe chaining API for structured JSON logging in Go, with support for contextual fields, multiple log levels, sampling, hooks, and integration with context.Context and net/http. It uses allocation-free JSON encoding and offers both JSON and CBOR output formats.

Quickstart

Get the zerolog source

Clone the repository and explore it locally.

terminalbash
git clone https://github.com/rs/zerolog.gitcd zerolog# follow the project's README for install & configuration

Need it deployed, integrated, or customized instead? DEV.co ships production installs.

Best use cases

High-throughput microservices

Production Go services requiring structured logging with minimal GC pressure and memory allocations. The zero-allocation design makes it ideal for latency-sensitive applications.

Cloud-native and containerized applications

Services deployed in Kubernetes or similar environments where JSON logs integrate natively with log aggregation stacks (ELK, Datadog, CloudWatch). Zerolog's JSON-first approach aligns with modern observability practices.

Structured logging with contextual tracing

Applications needing to correlate logs across request boundaries using context.Context integration and contextual fields. Useful for debugging distributed systems and request flows.

Implementation considerations

  • Chaining API requires explicit Msg() or Msgf() termination; missing it silently prevents logging with no compile error. Code review discipline is necessary.
  • Contextual field addition uses strongly-typed methods (Str, Int, Float64, etc.). Verify type correctness at call sites to avoid runtime issues.
  • Default output is os.Stderr. Explicitly configure output writers for production (file, syslog, network) to integrate with log aggregation systems.
  • Log sampling must be configured explicitly via zerolog.NewSampler(); default is no sampling. Adjust for high-volume production workloads.
  • Stack traces require opt-in via Stack() method and manual ErrorStackMarshaler configuration; they are not automatic on error logging.

When to avoid it — and what to weigh

  • Pretty-printed console logging is primary use case — Zerolog's ConsoleWriter is intentionally simple and inefficient. If development teams require advanced pretty-printing, filtering, or colored output, use stdlib log or alternative loggers.
  • Text-based log format required — Zerolog is JSON-first and does not provide efficient text logging. Projects requiring plain-text logs should consider stdlib log or logrus.
  • Implicit error handling preferred — Zerolog requires explicit chaining with Msg() or Msgf() calls; forgetting them silently skips logging with no compile-time error. Teams preferring implicit logging or automatic panic handling may find this error-prone.
  • Minimal external dependencies desired — While zerolog itself is lightweight, stack trace integration requires github.com/pkg/errors. Additional integration packages may introduce transitive dependencies.

License & commercial use

MIT License. Permissive OSI-approved license allowing commercial use, modification, and distribution with attribution and liability disclaimer. No restrictions on use or distribution model.

MIT License is permissive and clearly allows commercial use without additional licensing agreements or fees. Use in proprietary applications is permitted. No restrictions noted; standard attribution requirements apply.

DEV.co evaluation signals

Editorial assessment — not user reviews. Directional, with an explicit confidence level.

SignalAssessment
MaintenanceActive
DocumentationStrong
License clarityClear
Deployment complexityLow
DEV.co fitStrong
Assessment confidenceHigh
Security considerations

Zerolog itself has no built-in authentication, encryption, or access control—it is a local logging library. Security posture depends on output destination: ensure logs written to files have appropriate filesystem permissions; logs sent over network should use TLS; logs in cloud platforms should use IAM policies. No sensitive data masking is mentioned; sanitize secrets before logging. Reflect-free design reduces some attack surface compared to reflection-heavy loggers. Stack trace inclusion may expose internal implementation details; review stack output for sensitive information.

Alternatives to consider

Uber Zap

Pioneered zero-allocation structured logging in Go. Similar performance characteristics but larger feature set and more complex API. Zap may be overkill for simple cases; zerolog is simpler and faster for many workloads.

Go stdlib log/slog (1.21+)

Built-in structured logging with slog package. Less mature than zerolog, no zero-allocation guarantees, but eliminates external dependency. Suitable if targeting Go 1.21+ and avoiding third-party logging libraries.

logrus

Popular structured logging library with text and JSON output. Less performance-focused than zerolog; uses reflection and allocations. Better pretty-printing for development. Choose if text logging and ease-of-use outweigh performance needs.

Software development agency

Build on zerolog with DEV.co software developers

Zerolog delivers high-performance structured JSON logging with zero allocations. Whether you're building microservices, APIs, or cloud-native applications, our team can help you integrate and optimize logging for your infrastructure.

Talk to DEV.co

Related open-source tools

Surfaced by semantic similarity across the DEV.co open-source index.

Related on DEV.co

Explore the category and the services that help you build with it.

zerolog FAQ

What does 'zero allocation' mean in zerolog?
Zerolog uses a chaining API and avoids reflection to write JSON logs without heap allocations. This reduces garbage collection pressure and improves latency—critical for high-throughput services. Allocation varies by use case; 'zero' is a design goal, not guarantee.
Why do I need to call Msg() to log?
The chaining API builds the log event lazily. Msg() or Msgf() triggers the actual write. Omitting it silently discards the log with no compile error—a design choice prioritizing performance over safety. Code review discipline is required.
How do I output logs to files or cloud platforms?
Configure the logger's output writer. By default, zerolog writes to os.Stderr. Pass a file, os.Stdout, or custom io.Writer to zerolog.New(writer) or set a global writer. For cloud platforms, write to stdout and let container/platform capture logs.
Is zerolog production-ready?
Yes. Project created in 2017, actively maintained, 12k+ stars, widely adopted. However, verify the current release version and check GitHub issues for your specific use case before deployment.

Software development & web development with DEV.co

DEV.co is a software development agency delivering custom software development services to companies building on open source. Our software developers and web developers design, integrate, and ship production systems — spanning web development, APIs, AI, data, and cloud. If zerolog is part of your open-source observability roadmap, our team can implement, customize, migrate, and maintain it.

Need a production-ready logging solution for Go?

Zerolog delivers high-performance structured JSON logging with zero allocations. Whether you're building microservices, APIs, or cloud-native applications, our team can help you integrate and optimize logging for your infrastructure.