From 6ac23ce76f8732d80d3d07cff25ef105bb872c71 Mon Sep 17 00:00:00 2001 From: Abhinav Gupta Date: Sat, 9 Sep 2023 10:36:34 -0700 Subject: [PATCH] doc(WithLazy): Split into multiple paragraphs Split the doc strings into multiple paragraphs, adjust the wording. --- logger.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/logger.go b/logger.go index 475a4801e..a2f17f0d7 100644 --- a/logger.go +++ b/logger.go @@ -184,14 +184,19 @@ func (log *Logger) With(fields ...Field) *Logger { return l } -// WithLazy creates a child logger and lazily encodes structured context if the -// child logger is ever further chained with With() or is written to with any -// of the log level methods. Until the occurs, the logger may retain references -// to references in objects, etc, and logging will reflect the state of an object -// at the time of logging, not the time of WithLazy(). However, is a worthwhile -// performance optimisation if one creates a contextual logger and the likelihood -// of using it is low (e.g. in error or rarely taken branches). -// Fields added to the child don't affect the parent, and vice versa. +// 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 reflect the state of an object at the time of logging, +// not the time of WithLazy(). +// +// WithLazy provides a worthwhile performance optimization for contextual loggers +// when the likelihood of using the child logger is low, +// such as error paths and rarely taken branches. +// +// Similar to [With], fields added to the child don't affect the parent, and vice versa. func (log *Logger) WithLazy(fields ...Field) *Logger { if len(fields) == 0 { return log