From f78a71ff3c3c9123176c64530fa84e786ece3cf6 Mon Sep 17 00:00:00 2001 From: Chuck Ha Date: Fri, 25 Jan 2019 17:17:14 -0500 Subject: [PATCH] [clusterctl] log to stdout by default Signed-off-by: Chuck Ha --- WORKSPACE | 4 +-- cmd/clusterctl/cmd/BUILD.bazel | 3 -- cmd/clusterctl/cmd/logutil.go | 51 ---------------------------------- cmd/clusterctl/cmd/root.go | 2 +- 4 files changed, 3 insertions(+), 57 deletions(-) delete mode 100644 cmd/clusterctl/cmd/logutil.go diff --git a/WORKSPACE b/WORKSPACE index 0f58d49578b5..25a8fa008379 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -2,8 +2,8 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") http_archive( name = "io_bazel_rules_go", - url = "https://github.com/bazelbuild/rules_go/releases/download/0.16.5/rules_go-0.16.5.tar.gz", - sha256 = "7be7dc01f1e0afdba6c8eb2b43d2fa01c743be1b9273ab1eaf6c233df078d705", + url = "https://github.com/bazelbuild/rules_go/releases/download/0.16.6/rules_go-0.16.6.tar.gz", + sha256 = "ade51a315fa17347e5c31201fdc55aa5ffb913377aa315dceb56ee9725e620ee", ) http_archive( diff --git a/cmd/clusterctl/cmd/BUILD.bazel b/cmd/clusterctl/cmd/BUILD.bazel index f298d574ad15..4f793dba9abf 100644 --- a/cmd/clusterctl/cmd/BUILD.bazel +++ b/cmd/clusterctl/cmd/BUILD.bazel @@ -14,7 +14,6 @@ go_library( "create_cluster.go", "delete.go", "delete_cluster.go", - "logutil.go", "root.go", "validate.go", "validate_cluster.go", @@ -34,9 +33,7 @@ go_library( "//pkg/util:go_default_library", "//vendor/github.com/pkg/errors:go_default_library", "//vendor/github.com/spf13/cobra:go_default_library", - "//vendor/github.com/spf13/pflag:go_default_library", "//vendor/k8s.io/api/core/v1:go_default_library", - "//vendor/k8s.io/apimachinery/pkg/util/wait:go_default_library", "//vendor/k8s.io/client-go/tools/clientcmd:go_default_library", "//vendor/k8s.io/klog:go_default_library", "//vendor/sigs.k8s.io/controller-runtime/pkg/client:go_default_library", diff --git a/cmd/clusterctl/cmd/logutil.go b/cmd/clusterctl/cmd/logutil.go deleted file mode 100644 index 90b79071deea..000000000000 --- a/cmd/clusterctl/cmd/logutil.go +++ /dev/null @@ -1,51 +0,0 @@ -/* -Copyright 2018 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package cmd - -import ( - "flag" - "log" - "time" - - "github.com/spf13/pflag" - "k8s.io/apimachinery/pkg/util/wait" - "k8s.io/klog" -) - -var logFlushFreq = pflag.Duration("log-flush-frequency", 5*time.Second, "Maximum number of seconds between log flushes") - -// TODO(thockin): This is temporary until we agree on log dirs and put those into each cmd. -func init() { - flag.Set("logtostderr", "true") -} - -// KlogWriter serves as a bridge between the standard log package and the klog package. -type KlogWriter struct{} - -// Write implements the io.Writer interface. -func (writer KlogWriter) Write(data []byte) (n int, err error) { - klog.Info(string(data)) - return len(data), nil -} - -// InitLogs initializes logs the way we want for kubernetes. -func InitLogs() { - log.SetOutput(KlogWriter{}) - log.SetFlags(0) - // The default klog flush interval is 30 seconds, which is frighteningly long. - go wait.Until(klog.Flush, *logFlushFreq, wait.NeverStop) -} diff --git a/cmd/clusterctl/cmd/root.go b/cmd/clusterctl/cmd/root.go index d445187465ad..f4014a0031bb 100644 --- a/cmd/clusterctl/cmd/root.go +++ b/cmd/clusterctl/cmd/root.go @@ -50,6 +50,6 @@ func exitWithHelp(cmd *cobra.Command, err string) { func init() { klog.InitFlags(flag.CommandLine) + klog.SetOutput(os.Stdout) RootCmd.PersistentFlags().AddGoFlagSet(flag.CommandLine) - InitLogs() }