diff --git a/config/config.go b/config/config.go index 2b398c95be4..655c887c952 100644 --- a/config/config.go +++ b/config/config.go @@ -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) @@ -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) diff --git a/config/options.go b/config/options.go index bdf6780c22a..4d88f5e928d 100644 --- a/config/options.go +++ b/config/options.go @@ -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. @@ -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{} diff --git a/config/options_test.go b/config/options_test.go index c9af321e505..52b606de898 100644 --- a/config/options_test.go +++ b/config/options_test.go @@ -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") + } +}