From d1a9694ab474a0d8c24ebd0d1c0af4b232776c2e Mon Sep 17 00:00:00 2001 From: Gabe Cook Date: Wed, 29 Jun 2022 14:40:40 -0500 Subject: [PATCH] :sparkles: Add time taken to success logs --- cmd/dump/dump.go | 7 ++++++- cmd/restore/restore.go | 8 +++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/cmd/dump/dump.go b/cmd/dump/dump.go index 68d206b6..436ca791 100644 --- a/cmd/dump/dump.go +++ b/cmd/dump/dump.go @@ -143,6 +143,8 @@ func run(cmd *cobra.Command, args []string) (err error) { fmt.Println("::set-output name=filename::" + conf.Filename) } + var startTime = time.Now() + bar := progressbar.New(-1, "downloading") plogger := progressbar.NewBarSafeLogger(os.Stderr, bar) log.SetOutput(plogger) @@ -216,7 +218,10 @@ func run(cmd *cobra.Command, args []string) (err error) { } } - log.WithField("file", conf.Filename).Info("dump complete") + log.WithFields(log.Fields{ + "file": conf.Filename, + "in": time.Since(startTime).Truncate(10 * time.Millisecond), + }).Info("dump complete") return nil } diff --git a/cmd/restore/restore.go b/cmd/restore/restore.go index 31744726..d924c010 100644 --- a/cmd/restore/restore.go +++ b/cmd/restore/restore.go @@ -18,6 +18,7 @@ import ( "k8s.io/kubectl/pkg/util/term" "os" "strings" + "time" ) var Command = &cobra.Command{ @@ -126,6 +127,8 @@ func run(cmd *cobra.Command, args []string) (err error) { } } + startTime := time.Now() + bar := progressbar.New(-1, "uploading") errLog := progressbar.NewBarSafeLogger(os.Stderr, bar) outLog := progressbar.NewBarSafeLogger(os.Stdout, bar) @@ -193,7 +196,10 @@ func run(cmd *cobra.Command, args []string) (err error) { return err } - log.WithField("file", conf.Filename).Info("restore complete") + log.WithFields(log.Fields{ + "file": conf.Filename, + "in": time.Since(startTime).Truncate(10 * time.Millisecond), + }).Info("restore complete") return nil }