drop std' logger in favor of jww one

This commit is contained in:
Quentin Burgess 2023-01-20 11:30:52 +01:00 committed by Márk Sági-Kazár
parent 98b1b9fd42
commit 24ece16a9a

View file

@ -25,7 +25,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"log"
"os" "os"
"path/filepath" "path/filepath"
"reflect" "reflect"
@ -205,7 +204,6 @@ type Viper struct {
automaticEnvApplied bool automaticEnvApplied bool
envKeyReplacer StringReplacer envKeyReplacer StringReplacer
allowEmptyEnv bool allowEmptyEnv bool
logMessage bool
parents []string parents []string
config map[string]interface{} config map[string]interface{}
@ -243,7 +241,6 @@ func New() *Viper {
v.aliases = make(map[string]string) v.aliases = make(map[string]string)
v.typeByDefValue = false v.typeByDefValue = false
v.logger = jwwLogger{} v.logger = jwwLogger{}
v.logMessage = true
v.resetEncoding() v.resetEncoding()
@ -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. // StringReplacer applies a set of replacements to a string.
type StringReplacer interface { type StringReplacer interface {
// Replace returns a copy of s with all replacements performed. // Replace returns a copy of s with all replacements performed.
@ -450,16 +439,17 @@ func (v *Viper) WatchConfig() {
initWG.Add(1) initWG.Add(1)
go func() { go func() {
watcher, err := newWatcher() watcher, err := newWatcher()
if err != nil && v.logMessage { if err != nil {
log.Fatal(err) v.logger.Error("failure to create watcher",
"msg", err.Error())
os.Exit(1)
} }
defer watcher.Close() defer watcher.Close()
// we have to watch the entire directory to pick up renames/atomic saves in a cross-platform way // we have to watch the entire directory to pick up renames/atomic saves in a cross-platform way
filename, err := v.getConfigFile() filename, err := v.getConfigFile()
if err != nil { if err != nil {
if v.logMessage { v.logger.Error("get config file",
log.Printf("error: %v\n", err) "msg", err.Error())
}
initWG.Done() initWG.Done()
return return
} }
@ -487,8 +477,9 @@ func (v *Viper) WatchConfig() {
(currentConfigFile != "" && currentConfigFile != realConfigFile) { (currentConfigFile != "" && currentConfigFile != realConfigFile) {
realConfigFile = currentConfigFile realConfigFile = currentConfigFile
err := v.ReadInConfig() err := v.ReadInConfig()
if err != nil && v.logMessage { if err != nil {
log.Printf("error reading config file: %v\n", err) v.logger.Error("reading config file",
"msg", err.Error())
} }
if v.onConfigChange != nil { if v.onConfigChange != nil {
v.onConfigChange(event) v.onConfigChange(event)
@ -499,8 +490,8 @@ func (v *Viper) WatchConfig() {
} }
case err, ok := <-watcher.Errors: case err, ok := <-watcher.Errors:
if ok && v.logMessage { // 'Errors' channel is not closed if ok { // 'Errors' channel is not closed
log.Printf("watcher error: %v\n", err) v.logger.Error("watcher error", "msg", err.Error())
} }
eventsWG.Done() eventsWG.Done()
return return