diff --git a/cmd/root.go b/cmd/root.go index 5000faa..55e4348 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -22,6 +22,7 @@ import ( "github.com/civo/cli/common" "github.com/civo/cli/config" "github.com/civo/cli/utility" + log "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -44,8 +45,10 @@ var completionCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) error { err := cmd.Help() if err != nil { + log.Error(err) return err } + log.Warn("A valid command not provided") return errors.New("a valid subcommand is required") }, } @@ -59,6 +62,7 @@ var completionBashCmd = &cobra.Command{ err := rootCmd.GenBashCompletion(os.Stdout) if err != nil { utility.Error("%s", err.Error()) + log.Fatal(err) os.Exit(1) } }, @@ -73,6 +77,7 @@ var completionFishCmd = &cobra.Command{ err := rootCmd.GenFishCompletion(os.Stdout, true) if err != nil { utility.Error("%s", err.Error()) + log.Fatal(err) os.Exit(1) } }, @@ -87,6 +92,7 @@ var completionPowerShellCmd = &cobra.Command{ err := rootCmd.GenPowerShellCompletion(os.Stdout) if err != nil { utility.Error("%s", err.Error()) + log.Fatal(err) os.Exit(1) } }, @@ -101,6 +107,7 @@ var completionZshCmd = &cobra.Command{ err := rootCmd.GenZshCompletion(os.Stdout) if err != nil { utility.Error("%s", err.Error()) + log.Fatal(err) os.Exit(1) } }, @@ -111,6 +118,7 @@ var completionZshCmd = &cobra.Command{ func Execute() { err := rootCmd.Execute() if err != nil { + log.Fatal(err) os.Exit(1) } } @@ -146,6 +154,10 @@ func init() { rootCmd.AddCommand(sshkey.SSHKeyCmd) rootCmd.AddCommand(teams.TeamsCmd) rootCmd.AddCommand(volume.VolumeCmd) + // To get the logs in JSON Format + log.SetFormatter(&log.JSONFormatter{}) + // Add this line for logging filename and line number! + log.SetReportCaller(true) // Add warning if the region is empty, for the user with the old config config.ReadConfig() diff --git a/go.mod b/go.mod index f3ab75c..ad1ee52 100644 --- a/go.mod +++ b/go.mod @@ -35,6 +35,8 @@ require ( gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect ) +require github.com/sirupsen/logrus v1.2.0 + require ( github.com/MichaelMure/go-term-text v0.2.7 // indirect github.com/alecthomas/chroma v0.7.1 // indirect @@ -46,6 +48,7 @@ require ( github.com/inconshreveable/mousetrap v1.0.0 // indirect github.com/klauspost/compress v1.4.1 // indirect github.com/klauspost/cpuid v1.2.0 // indirect + github.com/konsorten/go-windows-terminal-sequences v1.0.1 // indirect github.com/kyokomi/emoji v2.1.0+incompatible // indirect github.com/lucasb-eyer/go-colorful v1.0.3 // indirect github.com/mattn/go-isatty v0.0.14 // indirect