Fixed setting logging level of msgbus CLI client

This commit is contained in:
James Mills 2018-05-07 12:55:01 -07:00
parent 0215f6f9a8
commit f316d5b3cd
No known key found for this signature in database
GPG Key ID: AC4C014F1440EBD6

View File

@ -25,6 +25,14 @@ var RootCmd = &cobra.Command{
This lets you publish, subscribe and pull messages from a running msgbusd
instance. This is the reference implementation of using the msgbus client
library for publishing and subscribing to topics.`,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
// set logging level
if viper.GetBool("debug") {
log.SetLevel(log.DebugLevel)
} else {
log.SetLevel(log.InfoLevel)
}
},
}
// Execute adds all child commands to the root command
@ -60,13 +68,6 @@ func init() {
viper.BindPFlag("debug", RootCmd.PersistentFlags().Lookup("debug"))
viper.SetDefault("debug", false)
// set logging level
if viper.GetBool("debug") {
log.SetLevel(log.DebugLevel)
} else {
log.SetLevel(log.InfoLevel)
}
}
// initConfig reads in config file and ENV variables if set.