Repository navigation
what is the difference? zap or zap (sugared) #1459
icetech233
started this conversation in
General
Replies: 1 comment
|
Two log handles in zap, trading ergonomics for performance:
logger, _ := zap.NewProduction()
logger.Info("server started",
zap.String("host", "localhost"),
zap.Int("port", 8080),
)Fields must be typed explicitly. Zero allocations on the hot path. Use this in performance-critical code.
sugar := logger.Sugar()
// Printf-style
sugar.Infof("server started on %s:%d", host, port)
// Loosely-typed key-value pairs
sugar.Infow("server started", "host", "localhost", "port", 8080)Accepts When to use which:
You can switch between them for free: sugar := logger.Sugar() // Logger → SugaredLogger
logger = sugar.Desugar() // SugaredLogger → LoggerThe rule of thumb from the zap docs: use |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
what is the difference? zap or zap (sugared)
All reactions