Skip to content

Commit

Permalink
doc(WithLazy): Split into multiple paragraphs
Browse files Browse the repository at this point in the history
Split the doc strings into multiple paragraphs, adjust the wording.
  • Loading branch information
abhinav committed Sep 9, 2023
1 parent f600804 commit 6ac23ce
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6ac23ce

Please sign in to comment.