Skip to content

Commit fd006fe

Browse files
committed
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 <[email protected]>
1 parent 0e0d033 commit fd006fe

File tree

9 files changed

+11
-30
lines changed

9 files changed

+11
-30
lines changed

cmd/api/api.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929
"strings"
3030
"time"
3131

32-
k0slog "github.com/k0sproject/k0s/internal/pkg/log"
32+
internallog "github.com/k0sproject/k0s/internal/pkg/log"
3333
mw "github.com/k0sproject/k0s/internal/pkg/middleware"
3434
"github.com/k0sproject/k0s/pkg/apis/k0s/v1beta1"
3535
"github.com/k0sproject/k0s/pkg/config"
@@ -56,7 +56,7 @@ func NewAPICmd() *cobra.Command {
5656
Args: cobra.NoArgs,
5757
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
5858
logrus.SetOutput(cmd.OutOrStdout())
59-
k0slog.SetInfoLevel()
59+
internallog.SetInfoLevel()
6060
return config.CallParentPersistentPreRun(cmd, args)
6161
},
6262
RunE: func(cmd *cobra.Command, _ []string) error {

cmd/backup/backup_unix.go

-4
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@ func NewBackupCmd() *cobra.Command {
4343
Use: "backup",
4444
Short: "Back-Up k0s configuration. Must be run as root (or with sudo)",
4545
Args: cobra.NoArgs,
46-
PreRun: func(cmd *cobra.Command, args []string) {
47-
// ensure logs don't mess up output
48-
logrus.SetOutput(cmd.ErrOrStderr())
49-
},
5046
RunE: func(cmd *cobra.Command, _ []string) error {
5147
opts, err := config.GetCmdOpts(cmd)
5248
if err != nil {

cmd/controller/controller.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import (
3434
workercmd "github.com/k0sproject/k0s/cmd/worker"
3535
"github.com/k0sproject/k0s/internal/pkg/dir"
3636
"github.com/k0sproject/k0s/internal/pkg/file"
37-
k0slog "github.com/k0sproject/k0s/internal/pkg/log"
37+
internallog "github.com/k0sproject/k0s/internal/pkg/log"
3838
"github.com/k0sproject/k0s/internal/pkg/sysinfo"
3939
"github.com/k0sproject/k0s/internal/sync/value"
4040
"github.com/k0sproject/k0s/pkg/apis/k0s/v1beta1"
@@ -83,7 +83,7 @@ func NewControllerCmd() *cobra.Command {
8383
Args: cobra.MaximumNArgs(1),
8484
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
8585
logrus.SetOutput(cmd.OutOrStdout())
86-
k0slog.SetInfoLevel()
86+
internallog.SetInfoLevel()
8787
return config.CallParentPersistentPreRun(cmd, args)
8888
},
8989
RunE: func(cmd *cobra.Command, args []string) error {

cmd/etcd/list.go

-5
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222

2323
"github.com/k0sproject/k0s/pkg/config"
2424
"github.com/k0sproject/k0s/pkg/etcd"
25-
"github.com/sirupsen/logrus"
2625

2726
"github.com/spf13/cobra"
2827
)
@@ -32,10 +31,6 @@ func etcdListCmd() *cobra.Command {
3231
Use: "member-list",
3332
Short: "List etcd cluster members (JSON encoded)",
3433
Args: cobra.NoArgs,
35-
PreRun: func(cmd *cobra.Command, args []string) {
36-
// ensure logs don't mess up the output
37-
logrus.SetOutput(cmd.ErrOrStderr())
38-
},
3934
RunE: func(cmd *cobra.Command, _ []string) error {
4035
opts, err := config.GetCmdOpts(cmd)
4136
if err != nil {

cmd/kubeconfig/admin.go

-5
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626

2727
"k8s.io/client-go/tools/clientcmd"
2828

29-
"github.com/sirupsen/logrus"
3029
"github.com/spf13/cobra"
3130
)
3231

@@ -39,10 +38,6 @@ func kubeConfigAdminCmd() *cobra.Command {
3938
$ export KUBECONFIG=~/.kube/config
4039
$ kubectl get nodes`,
4140
Args: cobra.NoArgs,
42-
PreRun: func(cmd *cobra.Command, args []string) {
43-
// ensure logs don't mess up the output
44-
logrus.SetOutput(cmd.ErrOrStderr())
45-
},
4641
RunE: func(cmd *cobra.Command, _ []string) error {
4742
opts, err := config.GetCmdOpts(cmd)
4843
if err != nil {

cmd/kubeconfig/create.go

-5
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828
"k8s.io/client-go/tools/clientcmd"
2929
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
3030

31-
"github.com/sirupsen/logrus"
3231
"github.com/spf13/cobra"
3332
)
3433

@@ -46,10 +45,6 @@ Note: A certificate once signed cannot be revoked for a particular user`,
4645
4746
optionally add groups:
4847
$ k0s kubeconfig create username --groups [groups]`,
49-
PreRun: func(cmd *cobra.Command, args []string) {
50-
// ensure logs don't mess up the output
51-
logrus.SetOutput(cmd.ErrOrStderr())
52-
},
5348
Args: cobra.ExactArgs(1),
5449
RunE: func(cmd *cobra.Command, args []string) error {
5550
username := args[0]

cmd/root.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import (
4242
"github.com/k0sproject/k0s/cmd/validate"
4343
"github.com/k0sproject/k0s/cmd/version"
4444
"github.com/k0sproject/k0s/cmd/worker"
45-
k0slog "github.com/k0sproject/k0s/internal/pkg/log"
45+
internallog "github.com/k0sproject/k0s/internal/pkg/log"
4646
"github.com/k0sproject/k0s/pkg/build"
4747
"github.com/k0sproject/k0s/pkg/config"
4848

@@ -61,12 +61,12 @@ func NewRootCmd() *cobra.Command {
6161

6262
PersistentPreRun: func(cmd *cobra.Command, args []string) {
6363
if config.Verbose {
64-
k0slog.SetInfoLevel()
64+
internallog.SetInfoLevel()
6565
}
6666

6767
if config.Debug {
6868
// TODO: check if it actually works and is not overwritten by something else
69-
k0slog.SetDebugLevel()
69+
internallog.SetDebugLevel()
7070

7171
go func() {
7272
log := logrus.WithField("debug_server", config.DebugListenOn)

cmd/worker/worker.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"runtime"
2626
"syscall"
2727

28-
k0slog "github.com/k0sproject/k0s/internal/pkg/log"
28+
internallog "github.com/k0sproject/k0s/internal/pkg/log"
2929
"github.com/k0sproject/k0s/internal/pkg/sysinfo"
3030
"github.com/k0sproject/k0s/pkg/build"
3131
"github.com/k0sproject/k0s/pkg/component/iptables"
@@ -61,7 +61,7 @@ func NewWorkerCmd() *cobra.Command {
6161
Args: cobra.MaximumNArgs(1),
6262
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
6363
logrus.SetOutput(cmd.OutOrStdout())
64-
k0slog.SetInfoLevel()
64+
internallog.SetInfoLevel()
6565
return config.CallParentPersistentPreRun(cmd, args)
6666
},
6767
RunE: func(cmd *cobra.Command, args []string) error {

main.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ import (
2323
"strings"
2424

2525
"github.com/k0sproject/k0s/cmd"
26-
k0slog "github.com/k0sproject/k0s/internal/pkg/log"
26+
internallog "github.com/k0sproject/k0s/internal/pkg/log"
2727
)
2828

2929
//go:generate make codegen
3030

3131
func init() {
32-
k0slog.InitLogging()
32+
internallog.InitLogging()
3333
}
3434

3535
func main() {

0 commit comments

Comments
 (0)