5 structured logging packages for Go
Blog post from LogRocket
Logging, though seemingly simple, involves complex best practices such as considering log levels, structuring logs, and adding context, which structured logging in JSON format facilitates by making log entries easily processable and filterable. In Golang, the inbuilt logging library produces unstructured logs, but structured logging packages like Zap, Zerolog, Logrus, apex/log, and Log15 enhance logging capabilities by allowing customization and contextualization of logs, thus improving debugging and performance. Zap, developed by Uber, offers high performance and flexibility with its Logger and SugaredLogger, while Zerolog prioritizes performance with a simple API and contextual logging. Logrus, though now in maintenance mode, is compatible with Golang's standard library logger and supports structured logging through the WithFields method. Apex/log, inspired by Logrus, simplifies its API and supports various handlers for centralizing logs, while Log15 focuses on readability with a key-value pair logging approach. Performance benchmarks reveal that Zerolog and Zap lead in efficiency, providing quicker logging processes with minimal allocations, making them preferable choices for performance-sensitive projects.