DEV Community

Santosh Kumar
Santosh Kumar

Posted on • Originally published at santoshk.dev

Best Logging Library for Golang

Introduction

I recently conducted a poll in the Go community regarding which logging library they use in their personal or professional project. The results were interesting. In this post I have jotted down the most favorite logging libraries and here is my opinion about them.

Poll Results

Here are the poll results which I conducted on r/golang, The Go Programming Language community on Twitter and my LinkedIn following.

Poll results on r/golang

Poll results on Twitter

Poll results on LinkedIn

Analysis of Results

Selection of the candidates

For choosing the candidates for the poll, I didn't do any thorough research. I was looking for a library to use in my project at work, and I ended up at sirupsen/logrus which was already being used by one of the dependencies in that project.

After reading the README of the logrus, I noted it was in maintenance mode and no new feature was actively being developed. I still decided to use this library because logrus is a mature project and it has all the features which a logging library should have.

logrus README recommended using other libraries such as Zerolog, Zap, and Apex.

I started a poll on r/golang with these four candidates, but also came to know about glog which was a go port of a C++ project by Google. I used that option in the poll conducted on LinkedIn.

I haven't personally used any one of them yet.

logrus

Let's talk about logrus first, it was the first library I landed upon when looking for one. The reason I looked at it first is that logrus was already one of the indirect dependencies of one of the dependencies in my project.

logrus stands 2nd in the place. zerolog is faster than logrus but there's a reason it stands seconds among 4. It has been there for a while.

zerolog

The main reason you'd want to use zerolog if you are switching from logrus is the performance. Go is blazingly fast; but if your logger is making it slow, your application gets no benefit from being implemented in Go.

This is what zerolog's README says:

The zerolog package provides a fast and simple logger dedicated to JSON output.

Zerolog's API is designed to provide both a great developer experience and stunning performance. Its unique chaining API allows zerolog to write JSON (or CBOR) log events by avoiding allocations and reflection.

zap

zap is probably the most loved logging library for Go. Among 817 people who have voted on r/golang, 315 voted for zap.

According to the stats on their GitHub, zap is the fastest logger available there.

Also, zap only supports the two most recent minor versions of Go. So you might be locked with an older version of zap if your project for some reason is not able to update to the latest version of Go.

Conclusion

To have an opinion, I feel that I use them all before coming to a conclusion. But after this poll, I think I'm going to start using zap right away. What is your opinion? Why factor was responsible when you were choosing your logging library.

Top comments (0)