Skip to content

Commit

Permalink
Add option for configuring initial fields on the logger (#244)
Browse files Browse the repository at this point in the history
* Add option for configuring initial fields on the logger

* Add doc string for WithInitialFields()
  • Loading branch information
jirwin authored Oct 10, 2024
1 parent 2bdcdc6 commit 79182ad
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ func WithOutputPaths(paths []string) Option {
}
}

// WithInitialFields allows the logger to be configured with static fields at creation time.
// This is useful for setting fields that are constant across all log messages.
func WithInitialFields(fields map[string]interface{}) Option {
return func(c *zap.Config) {
c.InitialFields = fields
}
}

// Init creates a new zap logger and attaches it to the provided context.
func Init(ctx context.Context, opts ...Option) (context.Context, error) {
zc := zap.NewProductionConfig()
Expand Down

0 comments on commit 79182ad

Please sign in to comment.