Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

add:viper: allow to disable internal log messages #1483

Merged
merged 3 commits into from
May 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions viper.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"errors"
"fmt"
"io"
"log"
"os"
"path/filepath"
"reflect"
Expand Down Expand Up @@ -434,13 +433,14 @@ func (v *Viper) WatchConfig() {
go func() {
watcher, err := newWatcher()
if err != nil {
log.Fatal(err)
v.logger.Error(fmt.Sprintf("failed to create watcher: %s", err))
os.Exit(1)
}
defer watcher.Close()
// we have to watch the entire directory to pick up renames/atomic saves in a cross-platform way
filename, err := v.getConfigFile()
if err != nil {
log.Printf("error: %v\n", err)
v.logger.Error(fmt.Sprintf("get config file: %s", err))
initWG.Done()
return
}
Expand Down Expand Up @@ -469,7 +469,7 @@ func (v *Viper) WatchConfig() {
realConfigFile = currentConfigFile
err := v.ReadInConfig()
if err != nil {
log.Printf("error reading config file: %v\n", err)
v.logger.Error(fmt.Sprintf("read config file: %s", err))
}
if v.onConfigChange != nil {
v.onConfigChange(event)
Expand All @@ -481,7 +481,7 @@ func (v *Viper) WatchConfig() {

case err, ok := <-watcher.Errors:
if ok { // 'Errors' channel is not closed
log.Printf("watcher error: %v\n", err)
v.logger.Error(fmt.Sprintf("watcher error: %s", err))
}
eventsWG.Done()
return
Expand Down