Skip to content

Commit

Permalink
Starting with Logging
Browse files Browse the repository at this point in the history
Signed-off-by: kitarp29 <kitarpsinghrajpoot@gmail.com>
  • Loading branch information
kitarp29 committed Aug 26, 2022
1 parent 9241325 commit 286aa6e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
12 changes: 12 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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")
},
}
Expand All @@ -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)
}
},
Expand All @@ -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)
}
},
Expand All @@ -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)
}
},
Expand All @@ -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)
}
},
Expand All @@ -111,6 +118,7 @@ var completionZshCmd = &cobra.Command{
func Execute() {
err := rootCmd.Execute()
if err != nil {
log.Fatal(err)
os.Exit(1)
}
}
Expand Down Expand Up @@ -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()
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 286aa6e

Please sign in to comment.