DEV Community

Nishant Modak for Last9

Posted on

Logging in Golang

Practical insights into Golang logging, including how to use the log package, popular third-party libraries, and tips for structured logging.

Table of Contents

  • Introduction to Golang Logging
  • The Standard Library: log Package How I Learned to Stop Worrying and Love fmt.Println()
  • Popular Third-Party Logging Libraries Because Reinventing the wheel is so 2000s
  • Structured Logging in Go JSON: Its whats for dinner
  • Configuring Log Levels and Output Formats Choosing your adventure
  • Integrating with Observability Platforms Because logs are lonely without metrics and traces
  • Best Practices and Performance Considerations How to not shoot yourself in the foot
  • Real-World Examples I really have used this stuff myself
  • Conclusion Log everything; but log it right with a schema (Otel)

Golang logging guide for developers

Top comments (3)

Collapse
 
goodevilgenius profile image
Dan Jones

Pretty surprised this article didn't mention slog, the stdlib structured logging package. It's a fairly recent addition, the 3rd party structured loggers all predate it, but it's built-in.

Personally, I'm a big fan of zerolog (which the article does mention). It's fast, and for me, fairly intuitive. And it feels a lot better using properly typed methods, rather than a method that just accepts interface{} for everything.

Collapse
 
nishantmodak profile image
Nishant Modak

Added an updated section and included a comparison table. Hopefully makes it easier! Comparison of golang logging

Collapse
 
nishantmodak profile image
Nishant Modak

Great point Dan! Completely missed mentioning it.

Let me include an update to article and cover slog.