From fd006fec2e728d6be06e9256d104fc642f074373 Mon Sep 17 00:00:00 2001 From: Tom Wieczorek Date: Fri, 20 Dec 2024 10:11:41 +0100 Subject: [PATCH] Remove redundant logrus.SetOutput(stderr) statements Logrus writes to stderr by default, and k0s doesn't change this in its initialization process. Only the few long-running sub-commands change this to stdout themselves. Signed-off-by: Tom Wieczorek --- cmd/api/api.go | 4 ++-- cmd/backup/backup_unix.go | 4 ---- cmd/controller/controller.go | 4 ++-- cmd/etcd/list.go | 5 ----- cmd/kubeconfig/admin.go | 5 ----- cmd/kubeconfig/create.go | 5 ----- cmd/root.go | 6 +++--- cmd/worker/worker.go | 4 ++-- main.go | 4 ++-- 9 files changed, 11 insertions(+), 30 deletions(-) diff --git a/cmd/api/api.go b/cmd/api/api.go index 5961743f2adf..7c7815bb9817 100644 --- a/cmd/api/api.go +++ b/cmd/api/api.go @@ -29,7 +29,7 @@ import ( "strings" "time" - k0slog "github.com/k0sproject/k0s/internal/pkg/log" + internallog "github.com/k0sproject/k0s/internal/pkg/log" mw "github.com/k0sproject/k0s/internal/pkg/middleware" "github.com/k0sproject/k0s/pkg/apis/k0s/v1beta1" "github.com/k0sproject/k0s/pkg/config" @@ -56,7 +56,7 @@ func NewAPICmd() *cobra.Command { Args: cobra.NoArgs, PersistentPreRunE: func(cmd *cobra.Command, args []string) error { logrus.SetOutput(cmd.OutOrStdout()) - k0slog.SetInfoLevel() + internallog.SetInfoLevel() return config.CallParentPersistentPreRun(cmd, args) }, RunE: func(cmd *cobra.Command, _ []string) error { diff --git a/cmd/backup/backup_unix.go b/cmd/backup/backup_unix.go index dd80d8443c6c..63df8ac32b68 100644 --- a/cmd/backup/backup_unix.go +++ b/cmd/backup/backup_unix.go @@ -43,10 +43,6 @@ func NewBackupCmd() *cobra.Command { Use: "backup", Short: "Back-Up k0s configuration. Must be run as root (or with sudo)", Args: cobra.NoArgs, - PreRun: func(cmd *cobra.Command, args []string) { - // ensure logs don't mess up output - logrus.SetOutput(cmd.ErrOrStderr()) - }, RunE: func(cmd *cobra.Command, _ []string) error { opts, err := config.GetCmdOpts(cmd) if err != nil { diff --git a/cmd/controller/controller.go b/cmd/controller/controller.go index 9c033c56e9ed..7315eb4a5730 100644 --- a/cmd/controller/controller.go +++ b/cmd/controller/controller.go @@ -34,7 +34,7 @@ import ( workercmd "github.com/k0sproject/k0s/cmd/worker" "github.com/k0sproject/k0s/internal/pkg/dir" "github.com/k0sproject/k0s/internal/pkg/file" - k0slog "github.com/k0sproject/k0s/internal/pkg/log" + internallog "github.com/k0sproject/k0s/internal/pkg/log" "github.com/k0sproject/k0s/internal/pkg/sysinfo" "github.com/k0sproject/k0s/internal/sync/value" "github.com/k0sproject/k0s/pkg/apis/k0s/v1beta1" @@ -83,7 +83,7 @@ func NewControllerCmd() *cobra.Command { Args: cobra.MaximumNArgs(1), PersistentPreRunE: func(cmd *cobra.Command, args []string) error { logrus.SetOutput(cmd.OutOrStdout()) - k0slog.SetInfoLevel() + internallog.SetInfoLevel() return config.CallParentPersistentPreRun(cmd, args) }, RunE: func(cmd *cobra.Command, args []string) error { diff --git a/cmd/etcd/list.go b/cmd/etcd/list.go index 61e7bb324f67..074ecdc972e4 100644 --- a/cmd/etcd/list.go +++ b/cmd/etcd/list.go @@ -22,7 +22,6 @@ import ( "github.com/k0sproject/k0s/pkg/config" "github.com/k0sproject/k0s/pkg/etcd" - "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -32,10 +31,6 @@ func etcdListCmd() *cobra.Command { Use: "member-list", Short: "List etcd cluster members (JSON encoded)", Args: cobra.NoArgs, - PreRun: func(cmd *cobra.Command, args []string) { - // ensure logs don't mess up the output - logrus.SetOutput(cmd.ErrOrStderr()) - }, RunE: func(cmd *cobra.Command, _ []string) error { opts, err := config.GetCmdOpts(cmd) if err != nil { diff --git a/cmd/kubeconfig/admin.go b/cmd/kubeconfig/admin.go index e96f5fcb921f..754ada5f6c96 100644 --- a/cmd/kubeconfig/admin.go +++ b/cmd/kubeconfig/admin.go @@ -26,7 +26,6 @@ import ( "k8s.io/client-go/tools/clientcmd" - "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -39,10 +38,6 @@ func kubeConfigAdminCmd() *cobra.Command { $ export KUBECONFIG=~/.kube/config $ kubectl get nodes`, Args: cobra.NoArgs, - PreRun: func(cmd *cobra.Command, args []string) { - // ensure logs don't mess up the output - logrus.SetOutput(cmd.ErrOrStderr()) - }, RunE: func(cmd *cobra.Command, _ []string) error { opts, err := config.GetCmdOpts(cmd) if err != nil { diff --git a/cmd/kubeconfig/create.go b/cmd/kubeconfig/create.go index 6a50066ee783..3e26b71c752f 100644 --- a/cmd/kubeconfig/create.go +++ b/cmd/kubeconfig/create.go @@ -28,7 +28,6 @@ import ( "k8s.io/client-go/tools/clientcmd" clientcmdapi "k8s.io/client-go/tools/clientcmd/api" - "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -46,10 +45,6 @@ Note: A certificate once signed cannot be revoked for a particular user`, optionally add groups: $ k0s kubeconfig create username --groups [groups]`, - PreRun: func(cmd *cobra.Command, args []string) { - // ensure logs don't mess up the output - logrus.SetOutput(cmd.ErrOrStderr()) - }, Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { username := args[0] diff --git a/cmd/root.go b/cmd/root.go index a4b8f164c4c0..88ac1bcb19df 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -42,7 +42,7 @@ import ( "github.com/k0sproject/k0s/cmd/validate" "github.com/k0sproject/k0s/cmd/version" "github.com/k0sproject/k0s/cmd/worker" - k0slog "github.com/k0sproject/k0s/internal/pkg/log" + internallog "github.com/k0sproject/k0s/internal/pkg/log" "github.com/k0sproject/k0s/pkg/build" "github.com/k0sproject/k0s/pkg/config" @@ -61,12 +61,12 @@ func NewRootCmd() *cobra.Command { PersistentPreRun: func(cmd *cobra.Command, args []string) { if config.Verbose { - k0slog.SetInfoLevel() + internallog.SetInfoLevel() } if config.Debug { // TODO: check if it actually works and is not overwritten by something else - k0slog.SetDebugLevel() + internallog.SetDebugLevel() go func() { log := logrus.WithField("debug_server", config.DebugListenOn) diff --git a/cmd/worker/worker.go b/cmd/worker/worker.go index 13c03c0c36ad..ffc912dcb466 100644 --- a/cmd/worker/worker.go +++ b/cmd/worker/worker.go @@ -25,7 +25,7 @@ import ( "runtime" "syscall" - k0slog "github.com/k0sproject/k0s/internal/pkg/log" + internallog "github.com/k0sproject/k0s/internal/pkg/log" "github.com/k0sproject/k0s/internal/pkg/sysinfo" "github.com/k0sproject/k0s/pkg/build" "github.com/k0sproject/k0s/pkg/component/iptables" @@ -61,7 +61,7 @@ func NewWorkerCmd() *cobra.Command { Args: cobra.MaximumNArgs(1), PersistentPreRunE: func(cmd *cobra.Command, args []string) error { logrus.SetOutput(cmd.OutOrStdout()) - k0slog.SetInfoLevel() + internallog.SetInfoLevel() return config.CallParentPersistentPreRun(cmd, args) }, RunE: func(cmd *cobra.Command, args []string) error { diff --git a/main.go b/main.go index 2ea483358293..007a235e2fad 100644 --- a/main.go +++ b/main.go @@ -23,13 +23,13 @@ import ( "strings" "github.com/k0sproject/k0s/cmd" - k0slog "github.com/k0sproject/k0s/internal/pkg/log" + internallog "github.com/k0sproject/k0s/internal/pkg/log" ) //go:generate make codegen func init() { - k0slog.InitLogging() + internallog.InitLogging() } func main() {