Skip to content

Commit

Permalink
Fix log level setting from cli/config/env var (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
diogomatsubara authored Nov 14, 2023
1 parent 081d23b commit 1b0ecc4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func Execute() {
}

func init() {
rootCmd.PersistentFlags().StringVar(&logLevel, "log-level", "info", "set logging level - debug, trace")
rootCmd.PersistentFlags().StringVar(&logLevel, "log-level", "", "set logging level - info, debug, trace")
rootCmd.PersistentFlags().StringVarP(&cfgFile, "config-file", "c", "", "Syncer configuration file")
rootCmd.PersistentFlags().StringVar(&inventoryKind, "inventory", "serverservice", "Inventory to publish firmwares.")
}
9 changes: 6 additions & 3 deletions internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ func New(ctx context.Context, inventoryKind types.InventoryKind, cfgFile, logLev
return nil, err
}

switch types.LogLevel(logLevel) {
// CLI parameter takes precedence over config and env vars
if logLevel != "" {
app.Config.LogLevel = logLevel
}

switch types.LogLevel(app.Config.LogLevel) {
case types.LogLevelDebug:
app.Logger.Level = logrus.DebugLevel
case types.LogLevelTrace:
Expand Down Expand Up @@ -183,8 +188,6 @@ func (a *App) LoadConfiguration(cfgFile string, inventoryKind types.InventoryKin
}
}

a.v.SetDefault("log.level", "info")

if err := a.envBindVars(); err != nil {
return errors.Wrap(config.ErrConfig, "env var bind error: "+err.Error())
}
Expand Down

0 comments on commit 1b0ecc4

Please sign in to comment.