I asked thousands of Gopher's what log library they used with Golang, and was really surprised by the results!

Which log library should I use in Go?


I asked thousands of Gophers which log library they used with Golang, and was really surprised by the results! a tweet asking go users what log library they used

It seems that an awful lot of people still continue to use rs/zerolog and uber-go/zap as their logging library of choice in Go.

Tons of folks are using slog from the standard library too. For the folks not using slog, a high proportion of them said they are only not using it because slog didn’t exist when they started their project. This makes sense to me- I’m not sure if it’s worth the effort to pull out their current logging infrastructure.

Why does it matter which logger I use in Go?

In most cases, it probably doesn’t. However, if you are building for performance then having a logger that does not allocate, slows down your program as little as possible, and has the ability to use in a structured way is important.

Which Go logging library is the fastest?

According to Uber-go’s benchmarks, rs/zerolog is the fastest in pretty much all scenarios.

logging benchmarks showing rs/zerolog is the fastest

So I should use zerolog?

Maybe.

Generally I try to aim for as few dependencies as possible, as it’s something else to be managed. In my own use, slog has been more than fine. If you hit a juncture where logging is a bottleneck, experimenting with zerolog could be worth it! I would bet in most cases you could solve logging bottlenecks by either removing logs, or “tuning down” the log mode.

What do you mean by “tuning down”?

Logging should always be done as part of a well-thought-out logging strategy. If you don’t have one, I’ll teach you how to create one in my debugging course (also available as a book here).