Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func New(opts ...Option) Config {
merge: func(dst, src any) error {
return mergo.Map(dst, src, mergo.WithOverride)
},
printLoadedDebugLog: true,
}
for _, opt := range opts {
opt(&o)
Expand Down Expand Up @@ -99,8 +100,10 @@ func (c *config) Load() error {
if err != nil {
return err
}
for _, v := range kvs {
log.Debugf("config loaded: %s format: %s", v.Key, v.Format)
if c.opts.printLoadedDebugLog {
for _, v := range kvs {
log.Debugf("config loaded: %s format: %s", v.Key, v.Format)
}
}
if err = c.reader.Merge(kvs...); err != nil {
log.Errorf("failed to merge config source: %v", err)
Expand Down
18 changes: 14 additions & 4 deletions config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ type Merge func(dst, src any) error
type Option func(*options)

type options struct {
sources []Source
decoder Decoder
resolver Resolver
merge Merge
sources []Source
decoder Decoder
resolver Resolver
merge Merge
printLoadedDebugLog bool
}

// WithSource with config source.
Expand All @@ -35,6 +36,15 @@ func WithSource(s ...Source) Option {
}
}

// WithPrintLoadedDebugLog with config print loaded debug log.
// Default is true.
// When printLoadedDebugLog is set to false, the loaded configuration will not be printed in the log.
func WithPrintLoadedDebugLog(printLoadedDebugLog bool) Option {
return func(o *options) {
o.printLoadedDebugLog = printLoadedDebugLog
}
}

// WithDecoder with config decoder.
// DefaultDecoder behavior:
// If KeyValue.Format is non-empty, then KeyValue.Value will be deserialized into map[string]interface{}
Expand Down
12 changes: 12 additions & 0 deletions config/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,3 +395,15 @@ func TestWithMergeFunc(t *testing.T) {
t.Fatal("c.merge is nil")
}
}

func TestWithPrintLoadedDebugLog(t *testing.T) {
c := &options{}
WithPrintLoadedDebugLog(true)(c)
if !c.printLoadedDebugLog {
t.Fatal("c.printLoadedDebugLog is false")
}
WithPrintLoadedDebugLog(false)(c)
if c.printLoadedDebugLog {
t.Fatal("c.printLoadedDebugLog is true")
}
}
Loading