From 49e119bd9bbb4f2d7a032da03f7d071f76cd1284 Mon Sep 17 00:00:00 2001 From: Benjamin Wenger <ben@elixxir.ioo> Date: Fri, 26 Feb 2021 15:12:22 -0800 Subject: [PATCH] fixed the log level flags --- README.md | 3 ++- cmd/root.go | 14 ++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 7986edf64..0aa1f5f36 100644 --- a/README.md +++ b/README.md @@ -182,7 +182,8 @@ Flags: --unsafe-channel-creation Turns off the user identity authenticated channel check, automatically approving authenticated channels - -v, --verbose Verbose mode for debugging + -v, --logLevel Level of debugging to print (0 = info, + 1 = debug, >1 = trace). (Default info) --waitTimeout uint The number of seconds to wait for messages to arrive (default 15) -w, --writeContact string Write the contact file for this user to this diff --git a/cmd/root.go b/cmd/root.go index a5b550f5e..b65e68cd5 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -260,7 +260,7 @@ func printRoundResults(allRoundsSucceeded, timedOut bool, } func createClient() *api.Client { - initLog(viper.GetBool("verbose"), viper.GetString("log")) + initLog(viper.GetUint("logLevel"), viper.GetString("log")) jww.INFO.Printf(Version()) pass := viper.GetString("password") @@ -547,7 +547,7 @@ func getUIDFromString(idStr string) *id.ID { return ID } -func initLog(verbose bool, logPath string) { +func initLog(threshold uint, logPath string) { if logPath != "-" && logPath != "" { // Disable stdout output jww.SetStdoutOutput(ioutil.Discard) @@ -560,14 +560,16 @@ func initLog(verbose bool, logPath string) { jww.SetLogOutput(logOutput) } - if verbose { + if threshold>1{ jww.SetStdoutThreshold(jww.LevelTrace) jww.SetLogThreshold(jww.LevelTrace) - } else { + }else if threshold == 1{ + jww.SetStdoutThreshold(jww.LevelDebug) + jww.SetLogThreshold(jww.LevelDebug) + }else{ jww.SetStdoutThreshold(jww.LevelInfo) jww.SetLogThreshold(jww.LevelInfo) } - } func isValidUser(usr []byte) (bool, *id.ID) { @@ -615,7 +617,7 @@ func init() { // Here you will define your flags and configuration settings. // Cobra supports persistent flags, which, if defined here, // will be global for your application. - rootCmd.PersistentFlags().BoolP("verbose", "v", false, + rootCmd.PersistentFlags().UintP("logLevel", "v", 0, "Verbose mode for debugging") viper.BindPFlag("verbose", rootCmd.PersistentFlags().Lookup("verbose")) -- GitLab