Skip to content

Commit

Permalink
fix: Better output
Browse files Browse the repository at this point in the history
  • Loading branch information
NoUseFreak committed Dec 8, 2023
1 parent 690a46d commit bea890e
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion cmd/git-backup/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ import (
"github.com/stenic/go-git-backup/pkg/app"
)

var v string
var (
v string
logFormat string
)

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Expand All @@ -38,6 +41,7 @@ func Execute() {
viper.SetDefault("log.level", "info")

rootCmd.PersistentFlags().StringVarP(&v, "verbosity", "v", viper.GetString("log.level"), "Log level (debug, info, warn, error, fatal, panic")
rootCmd.PersistentFlags().StringVar(&logFormat, "log-format", "text", "Log format (text, json)")
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
Expand All @@ -55,5 +59,17 @@ func setUpLogs(out io.Writer, level string) error {
return err
}
logrus.SetLevel(lvl)

switch logFormat {
case "json":
logrus.SetFormatter(&logrus.JSONFormatter{})
case "text":
customFormatter := new(logrus.TextFormatter)
customFormatter.DisableTimestamp = true
logrus.SetFormatter(customFormatter)
default:
logrus.Error("Unknown log format: ", logFormat)
}

return nil
}

0 comments on commit bea890e

Please sign in to comment.