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 69fe011 commit 8a56791
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ var (
targetDir string
driverName string
// Extras
v string
dryRun bool
v string
dryRun bool
logFormat string
// Hidden
backupDate string
)
Expand All @@ -54,6 +55,7 @@ func init() {
// Extras
rootCmd.Flags().StringVarP(&v, "verbosity", "v", logrus.InfoLevel.String(), "Log level (debug, info, warn, error, fatal, panic")
rootCmd.Flags().BoolVar(&dryRun, "dry-run", false, "Don't change any files")
rootCmd.Flags().StringVar(&logFormat, "log-format", "text", "Log format (text, json)")

// Hidden
rootCmd.Flags().StringVar(&backupDate, "date", "", "Testing: Set time of the backup")
Expand Down Expand Up @@ -139,9 +141,16 @@ func setUpLogs(out io.Writer, level string) error {
}
logrus.SetLevel(lvl)

customFormatter := new(logrus.TextFormatter)
customFormatter.DisableTimestamp = true
logrus.SetFormatter(customFormatter)
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
}
Expand Down

0 comments on commit 8a56791

Please sign in to comment.