Skip to content

Commit

Permalink
Merge pull request #39 from milobella/fix/config
Browse files Browse the repository at this point in the history
fix: parsing of log level + configname
  • Loading branch information
celian-garcia authored Oct 5, 2022
2 parents c169f7d + bf8a9eb commit 3dd5d6d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ func (c Config) String() string {
}

type Server struct {
Port int `mapstructure:"port"`
LogLevel logrus.Level `mapstructure:"log_level"`
Port int `mapstructure:"port"`
LogLevel string `mapstructure:"log_level"`
}

type Tool struct {
Expand Down
12 changes: 10 additions & 2 deletions pkg/config/viper.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/spf13/viper"
)

const configName = "server"
const configName = "ability"

func Read(extensions ...interface{}) *Config {
e := enviper.New(viper.New())
Expand Down Expand Up @@ -39,7 +39,15 @@ func Read(extensions ...interface{}) *Config {
}
}

logrus.SetLevel(config.Server.LogLevel)
var level logrus.Level
level, err = logrus.ParseLevel(config.Server.LogLevel)
if err != nil {
logrus.SetLevel(logrus.InfoLevel)
logrus.WithError(err).Errorf("Error occured while parsing log level. Default to INFO")
} else {
logrus.SetLevel(level)
}

return &config
}

Expand Down

0 comments on commit 3dd5d6d

Please sign in to comment.