flake-profile-8-link
Frequently Asked Questions
Design
Why spend so much effort on logger performance?
Of course, most applications won't notice the impact of a slow logger: they already take tens or hundreds of milliseconds for each operation, so an extra millisecond doesn't matter.
On the other hand, why not make structured logging fast? The SugaredLogger
isn't any harder to use than other logging packages, and the Logger
makes
structured logging possible in performance-sensitive contexts. Across a fleet
of Go microservices, making each application even slightly more efficient adds
up quickly.
Logger
and SugaredLogger
interfaces?
Why aren't Unlike the familiar io.Writer
and http.Handler
, Logger
and
SugaredLogger
interfaces would include many methods. As Rob Pike points
out, "The bigger the interface, the weaker the abstraction."
Interfaces are also rigid — any change requires releasing a new major
version, since it breaks all third-party implementations.
Making the Logger
and SugaredLogger
concrete types doesn't sacrifice much
abstraction, and it lets us add methods without introducing breaking changes.
Your applications should define and depend upon an interface that includes
just the methods you use.
Why are some of my logs missing?
Logs are dropped intentionally by zap when sampling is enabled. The production
configuration (as returned by NewProductionConfig()
enables sampling which will
cause repeated logs within a second to be sampled. See more details on why sampling
is enabled in Why sample application logs.