MCPcopy
hub / github.com/uber-go/zap / WithLazy

Method WithLazy

logger.go:202–209  ·  view source on GitHub ↗

WithLazy creates a child logger and adds structured context to it lazily. The fields are evaluated only if the logger is further chained with [With] or is written to with any of the log level methods. Until that occurs, the logger may retain references to objects inside the fields, and logging will

(fields ...Field)

Source from the content-addressed store, hash-verified

200//
201// Similar to [With], fields added to the child don't affect the parent, and vice versa.
202func (log *Logger) WithLazy(fields ...Field) *Logger {
203 if len(fields) == 0 {
204 return log
205 }
206 return log.WithOptions(WrapCore(func(core zapcore.Core) zapcore.Core {
207 return zapcore.NewLazyWith(core, fields)
208 }))
209}
210
211// Level reports the minimum enabled level for this logger.
212//

Callers

nothing calls this directly

Calls 3

WithOptionsMethod · 0.95
NewLazyWithFunction · 0.92
WrapCoreFunction · 0.85

Tested by

no test coverage detected