From cc8e8a5787c5b9f7163e6ab9002ae4f8b1984d34 Mon Sep 17 00:00:00 2001 From: bdular Date: Wed, 19 Mar 2025 21:36:59 +0100 Subject: [PATCH 1/2] fix: use log instead of fmt --- cmd/agent.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/cmd/agent.go b/cmd/agent.go index 5a3f5ad68..d6b20f18e 100644 --- a/cmd/agent.go +++ b/cmd/agent.go @@ -89,12 +89,12 @@ WAIT: case s := <-signalCh: sig = s case err := <-agent.RetryJoinCh(): - fmt.Println("[ERR] agent: Retry join failed: ", err) + log.WithError(err).Error("agent: Retry join failed") return 1 case <-ShutdownCh: sig = os.Interrupt } - fmt.Printf("Caught signal: %v", sig) + log.Infof("Caught signal: %v", sig) // Check if this is a SIGHUP if sig == syscall.SIGHUP { @@ -111,8 +111,7 @@ WAIT: log.Info("agent: Gracefully shutting down agent...") go func() { if err := agent.Stop(); err != nil { - fmt.Printf("Error: %s", err) - log.Error(fmt.Sprintf("Error: %s", err)) + log.WithError(err).Error("unable to stop agent") return } }() @@ -145,7 +144,7 @@ WAIT: // handleReload is invoked when we should reload our configs, e.g. SIGHUP func handleReload() { - fmt.Println("Reloading configuration...") + log.Info("Reloading configuration...") initConfig() //Config reloading will also reload Notification settings agent.UpdateTags(config.Tags) From 39627b3e8c2e2650c2d649726ceb07fd3f1d45cc Mon Sep 17 00:00:00 2001 From: bdular Date: Wed, 19 Mar 2025 21:46:50 +0100 Subject: [PATCH 2/2] fix: replacing fmt.Prints with logrus --- cmd/keygen.go | 3 ++- cmd/leave.go | 1 + cmd/raft.go | 2 +- cmd/version.go | 11 +++++------ 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/cmd/keygen.go b/cmd/keygen.go index 839bd85a7..a62ea748d 100644 --- a/cmd/keygen.go +++ b/cmd/keygen.go @@ -6,6 +6,7 @@ import ( "errors" "fmt" + log "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -26,7 +27,7 @@ var keygenCmd = &cobra.Command{ return errors.New("couldn't read enough entropy. Generate more entropy") } - fmt.Println(base64.StdEncoding.EncodeToString(key)) + log.Info(base64.StdEncoding.EncodeToString(key)) return nil }, } diff --git a/cmd/leave.go b/cmd/leave.go index fe08eb66a..0d67be852 100644 --- a/cmd/leave.go +++ b/cmd/leave.go @@ -31,6 +31,7 @@ var leaveCmd = &cobra.Command{ return err } + log.Info("Left the cluster successfully") return nil }, } diff --git a/cmd/raft.go b/cmd/raft.go index ad23d7712..9c3790ec2 100644 --- a/cmd/raft.go +++ b/cmd/raft.go @@ -68,7 +68,7 @@ var raftRemovePeerCmd = &cobra.Command{ if err := gc.RaftRemovePeerByID(ip, peerID); err != nil { return err } - fmt.Println("Peer removed") + log.Info("Peer removed") return nil }, diff --git a/cmd/version.go b/cmd/version.go index 148e586a1..e7fd66eb5 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -1,10 +1,9 @@ package cmd import ( - "fmt" - "github.com/distribworks/dkron/v4/dkron" "github.com/hashicorp/serf/serf" + log "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -14,10 +13,10 @@ var versionCmd = &cobra.Command{ Short: "Show version", Long: `Show the version`, Run: func(cmd *cobra.Command, args []string) { - fmt.Printf("Name: %s\n", dkron.Name) - fmt.Printf("Version: %s\n", dkron.Version) - fmt.Printf("Codename: %s\n", dkron.Codename) - fmt.Printf("Agent Protocol: %d (Understands back to: %d)\n", + log.Infof("Name: %s\n", dkron.Name) + log.Infof("Version: %s\n", dkron.Version) + log.Infof("Codename: %s\n", dkron.Codename) + log.Infof("Agent Protocol: %d (Understands back to: %d)\n", serf.ProtocolVersionMax, serf.ProtocolVersionMin) }, }