Skip to content

Fix: Use log instead of fmt #1706

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions cmd/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
}()
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion cmd/keygen.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"fmt"

log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

Expand All @@ -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
},
}
Expand Down
1 change: 1 addition & 0 deletions cmd/leave.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var leaveCmd = &cobra.Command{
return err
}

log.Info("Left the cluster successfully")
return nil
},
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down
11 changes: 5 additions & 6 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -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"
)

Expand All @@ -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",
Comment on lines +16 to +19
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is showing the version, it's not logging, so no motivation to use log.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logrus will also output the version into the console/stdout. This was changed just to make things a bit more consistent

serf.ProtocolVersionMax, serf.ProtocolVersionMin)
},
}
Expand Down
Loading