Go logging libraries compared: slog, Zap, Zerolog, and six more
Compare nine Go logging options by API, output, and maintenance. See how a warning from Logrus, slog, Zerolog, or Zap reaches the collector.
If a checkout service already ships useful JSON logs, changing its Go logger means changing an input to every parser and alert downstream. An error message may look identical in the terminal while its severity field has changed from warning to WARN. A dashboard that filters on the old value quietly loses those events.
For a new service on Go 1.21 or later, I'd start with the standard library's log/slog. For an existing service, I'd start with a log sample from the collector and a profile of the application. Those tell you what the current logger costs and which parts of its output the rest of the system relies on.
Nine Go logging options and where they fit
| Package | Why teams reach for it | Boundary to check |
|---|---|---|
| slog | Standard-library structured logging with built-in text and JSON handlers | A different Handler can change field names and output behavior |
| Zerolog | Low-overhead chained events, JSON by default | A timestamp needs to be added to the event or bound to the logger |
| Zap | Typed fields in Logger, convenient key-value and formatting methods in SugaredLogger |
Compare the API and encoder you would actually run |
| Logrus | Existing WithFields calls, formatters, and hooks |
Maintenance mode covers fixes and interoperability work. Existing hooks may need a replacement on migration |
| Apex/log | Small structured API with separate handlers | Its JSON handler nests custom fields under fields. Its last tagged module release was in 2020 |
| Log15 | Logfmt output and composable handlers | v3 has a different module path. The project released v3.2.1 in May 2026 and suggests considering slog |
| Logf | A narrow logfmt API with default fields | Check the version you can pin and whether your collector handles its logfmt output |
| Phuslu/log | Chained structured events and a FileWriter with rotation |
If you write to a file, include rotation and collector behavior in the test |
| Logr | A logger API for code that lets the application choose the sink | Evaluate the injected LogSink for output and cost |
Logrus's maintenance status describes its scope. An older tag on Apex/log describes its release history. To estimate the work of migrating an existing service, check the dependency you build with, the hooks it runs, and the output the collector sees.
Keep the interface separate from the output
slog makes it easy to choose TextHandler for a terminal or JSONHandler for a collector. The same *slog.Logger can use a different slog.Handler later. A third-party logger needs a compatible handler or adapter. Changing the handler preserves the call sites that use the slog API, while field grouping, level mapping, and source information can still differ. Go slog package
The same distinction matters if you're writing a library or a controller. Where the host already supplies a logr.Logger, accept it and keep the application's sink. Kubernetes contextual logging uses the go-logr API. A controller can attach its resource name or reconciliation context without deciding which encoder runs across the process. Kubernetes contextual logging
For applications choosing an implementation directly, Zerolog's chained events and Zap's typed fields both give you control over encoding. Zap also offers SugaredLogger and runtime level changes with AtomicLevel. The useful difference is what the codebase can maintain. Pick the call pattern you will use and measure it with the same event fields.
Compare the costs your service actually pays
An encoder benchmark can tell you what one library spends turning a record into bytes. The result depends on field count and types, whether context fields are already attached, whether caller information is recorded, and where the bytes go. Upstream Zap benchmarks pin library versions and report separate cases. A number from one case belongs to that configuration. Zap benchmark suite
If logging shows up in a production profile, benchmark a representative event twice. A discard writer helps isolate encoding and allocation cost. The actual output path, such as container stdout or a rotating file, shows what happens when writes block or buffers fill. Match levels, fields, sampling, and concurrency. Record CPU, allocations, and latency under the same load. An allocation improvement can matter on a busy service even when it has little effect at low volume.
Run the same event through the old and new logger
The fixture sent one synthetic warning with the message checkout retry, an error, and numeric attempt=2. In a local Go 1.26.1 run, these were the relevant fields. The Zerolog fixture explicitly attached a timestamp. The Zap fixture used a JSON encoder with the production encoder configuration.
| Fixture | Time field | Severity value | Message field |
|---|---|---|---|
| Logrus 1.10.2 JSON formatter | time, RFC3339 |
warning |
msg |
| slog JSON handler | time, RFC3339 with fractional seconds in this run |
WARN |
msg |
Zerolog 1.35.1 with Timestamp() |
time, RFC3339 |
warn |
message |
| Zap 1.28.0 production JSON encoder | ts, numeric Unix seconds |
warn |
msg |
All four kept attempt numeric in this sample. A collector rule looking for level=warning would match the Logrus record and miss the other three raw records. A parser that expects a text timestamp in time also needs a mapping for Zap's numeric ts. The local test checks the output schema.
In Guance, DataKit can collect supported container stdout logs or tail files. Try representative lines from both versions in Pipeline and compare the parsed event time, severity, message, and business field types. For this warning, normalize the severity to the value your existing monitor expects before changing the logger. Include a record with a missing field and one with a stack trace if the application emits them. After the parser check, use the same query on a test source to verify the result before switching traffic. DataKit log collection · Guance Pipeline
Keep an existing logger when it meets the service's needs and the dependency can be maintained. For a new service, slog leaves room to change the handler later. Reach for Zerolog or Zap when a representative test gives you a reason, and keep Logr where the application framework already supplies it.
Implement structured logging with Go slog · Go logging with Zap · Go logging with Zerolog
Contact us
Join the community
to join the community
Try Guance
Start online and pay only for what you use.
Get startedChoose a Guance plan
