Skip to content

Commit

Permalink
drop std' logger in favor of jww one
Browse files Browse the repository at this point in the history
  • Loading branch information
burgesQ authored and sagikazarmark committed May 29, 2023
1 parent 98b1b9f commit 24ece16
Showing 1 changed file with 11 additions and 20 deletions.
31 changes: 11 additions & 20 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 @@ -205,7 +204,6 @@ type Viper struct {
automaticEnvApplied bool
envKeyReplacer StringReplacer
allowEmptyEnv bool
logMessage bool

parents []string
config map[string]interface{}
Expand Down Expand Up @@ -243,7 +241,6 @@ func New() *Viper {
v.aliases = make(map[string]string)
v.typeByDefValue = false
v.logger = jwwLogger{}
v.logMessage = true

v.resetEncoding()

Expand Down Expand Up @@ -272,14 +269,6 @@ func KeyDelimiter(d string) Option {
})
}

// DisableMessageLog block any kind of messages to be logged.
// By default, all messages are logged.
func DisableMessageLog() Option {
return optionFunc(func(v *Viper) {
v.logMessage = false
})
}

// StringReplacer applies a set of replacements to a string.
type StringReplacer interface {
// Replace returns a copy of s with all replacements performed.
Expand Down Expand Up @@ -450,16 +439,17 @@ func (v *Viper) WatchConfig() {
initWG.Add(1)
go func() {
watcher, err := newWatcher()
if err != nil && v.logMessage {
log.Fatal(err)
if err != nil {
v.logger.Error("failure to create watcher",
"msg", err.Error())
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 {
if v.logMessage {
log.Printf("error: %v\n", err)
}
v.logger.Error("get config file",
"msg", err.Error())
initWG.Done()
return
}
Expand Down Expand Up @@ -487,8 +477,9 @@ func (v *Viper) WatchConfig() {
(currentConfigFile != "" && currentConfigFile != realConfigFile) {
realConfigFile = currentConfigFile
err := v.ReadInConfig()
if err != nil && v.logMessage {
log.Printf("error reading config file: %v\n", err)
if err != nil {
v.logger.Error("reading config file",
"msg", err.Error())
}
if v.onConfigChange != nil {
v.onConfigChange(event)
Expand All @@ -499,8 +490,8 @@ func (v *Viper) WatchConfig() {
}

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

0 comments on commit 24ece16

Please sign in to comment.