Skip to content

Commit 3a5816c

Browse files
authored
Merge pull request #592 from replicatedhq/disable-client-go-logs
Disable client-go logging
2 parents a881877 + 7c74f8b commit 3a5816c

File tree

4 files changed

+36
-4
lines changed

4 files changed

+36
-4
lines changed

cmd/analyze/cli/root.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ import (
44
"os"
55
"strings"
66

7+
"github.com/go-logr/logr"
78
"github.com/replicatedhq/troubleshoot/pkg/k8sutil"
89
"github.com/replicatedhq/troubleshoot/pkg/logger"
910
"github.com/spf13/cobra"
1011
"github.com/spf13/viper"
12+
"k8s.io/klog/v2"
1113
)
1214

1315
func RootCmd() *cobra.Command {
@@ -18,7 +20,12 @@ func RootCmd() *cobra.Command {
1820
Long: `Run a series of analyzers on a support bundle archive`,
1921
SilenceUsage: true,
2022
PreRun: func(cmd *cobra.Command, args []string) {
21-
viper.BindPFlags(cmd.Flags())
23+
v := viper.GetViper()
24+
v.BindPFlags(cmd.Flags())
25+
26+
if !v.GetBool("debug") {
27+
klog.SetLogger(logr.Discard())
28+
}
2229
},
2330
RunE: func(cmd *cobra.Command, args []string) error {
2431
v := viper.GetViper()
@@ -32,6 +39,7 @@ func RootCmd() *cobra.Command {
3239
cobra.OnInitialize(initConfig)
3340

3441
cmd.Flags().String("analyzers", "", "filename or url of the analyzers to use")
42+
cmd.Flags().Bool("debug", false, "enable debug logging")
3543

3644
viper.BindPFlags(cmd.Flags())
3745

cmd/collect/cli/root.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ import (
44
"os"
55
"strings"
66

7+
"github.com/go-logr/logr"
78
"github.com/replicatedhq/troubleshoot/pkg/k8sutil"
89
"github.com/replicatedhq/troubleshoot/pkg/logger"
910
"github.com/spf13/cobra"
1011
"github.com/spf13/viper"
12+
"k8s.io/klog/v2"
1113
)
1214

1315
func RootCmd() *cobra.Command {
@@ -18,7 +20,12 @@ func RootCmd() *cobra.Command {
1820
Long: `Run a collector and output the results.`,
1921
SilenceUsage: true,
2022
PreRun: func(cmd *cobra.Command, args []string) {
21-
viper.BindPFlags(cmd.Flags())
23+
v := viper.GetViper()
24+
v.BindPFlags(cmd.Flags())
25+
26+
if !v.GetBool("debug") {
27+
klog.SetLogger(logr.Discard())
28+
}
2229
},
2330
RunE: func(cmd *cobra.Command, args []string) error {
2431
v := viper.GetViper()
@@ -39,6 +46,7 @@ func RootCmd() *cobra.Command {
3946
cmd.Flags().String("collector-pull-policy", "", "the pull policy of the collector image")
4047
cmd.Flags().String("selector", "", "selector (label query) to filter remote collection nodes on.")
4148
cmd.Flags().Bool("collect-without-permissions", false, "always generate a support bundle, even if it some require additional permissions")
49+
cmd.Flags().Bool("debug", false, "enable debug logging")
4250

4351
// hidden in favor of the `insecure-skip-tls-verify` flag
4452
cmd.Flags().Bool("allow-insecure-connections", false, "when set, do not verify TLS certs when retrieving spec and reporting results")

cmd/preflight/cli/root.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ import (
44
"os"
55
"strings"
66

7+
"github.com/go-logr/logr"
78
"github.com/replicatedhq/troubleshoot/pkg/k8sutil"
89
"github.com/spf13/cobra"
910
"github.com/spf13/viper"
11+
"k8s.io/klog/v2"
1012
)
1113

1214
func RootCmd() *cobra.Command {
@@ -18,7 +20,12 @@ func RootCmd() *cobra.Command {
1820
that a cluster meets the requirements to run an application.`,
1921
SilenceUsage: true,
2022
PreRun: func(cmd *cobra.Command, args []string) {
21-
viper.BindPFlags(cmd.Flags())
23+
v := viper.GetViper()
24+
v.BindPFlags(cmd.Flags())
25+
26+
if !v.GetBool("debug") {
27+
klog.SetLogger(logr.Discard())
28+
}
2229
},
2330
RunE: func(cmd *cobra.Command, args []string) error {
2431
v := viper.GetViper()
@@ -39,6 +46,7 @@ that a cluster meets the requirements to run an application.`,
3946
cmd.Flags().String("since-time", "", "force pod logs collectors to return logs after a specific date (RFC3339)")
4047
cmd.Flags().String("since", "", "force pod logs collectors to return logs newer than a relative duration like 5s, 2m, or 3h.")
4148
cmd.Flags().StringP("output", "o", "", "specify the output file path for the preflight checks")
49+
cmd.Flags().Bool("debug", false, "enable debug logging")
4250

4351
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
4452

cmd/troubleshoot/cli/root.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ import (
55
"os"
66
"strings"
77

8+
"github.com/go-logr/logr"
89
troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
910
"github.com/replicatedhq/troubleshoot/pkg/k8sutil"
1011
"github.com/replicatedhq/troubleshoot/pkg/logger"
1112
"github.com/spf13/cobra"
1213
"github.com/spf13/viper"
14+
"k8s.io/klog/v2"
1315
)
1416

1517
func RootCmd() *cobra.Command {
@@ -21,7 +23,12 @@ func RootCmd() *cobra.Command {
2123
from a server that can be used to assist when troubleshooting a Kubernetes cluster.`,
2224
SilenceUsage: true,
2325
PreRun: func(cmd *cobra.Command, args []string) {
24-
viper.BindPFlags(cmd.Flags())
26+
v := viper.GetViper()
27+
v.BindPFlags(cmd.Flags())
28+
29+
if !v.GetBool("debug") {
30+
klog.SetLogger(logr.Discard())
31+
}
2532
},
2633
RunE: func(cmd *cobra.Command, args []string) error {
2734
v := viper.GetViper()
@@ -43,6 +50,7 @@ from a server that can be used to assist when troubleshooting a Kubernetes clust
4350
cmd.Flags().String("since-time", "", "force pod logs collectors to return logs after a specific date (RFC3339)")
4451
cmd.Flags().String("since", "", "force pod logs collectors to return logs newer than a relative duration like 5s, 2m, or 3h.")
4552
cmd.Flags().StringP("output", "o", "", "specify the output file path for the support bundle")
53+
cmd.Flags().Bool("debug", false, "enable debug logging")
4654

4755
// hidden in favor of the `insecure-skip-tls-verify` flag
4856
cmd.Flags().Bool("allow-insecure-connections", false, "when set, do not verify TLS certs when retrieving spec and reporting results")

0 commit comments

Comments
 (0)