Browse code

Merge pull request #8024 from stevekuznetsov/skuznets/glog

Merged by openshift-bot

OpenShift Bot authored on 2016/05/02 23:51:20
Showing 5 changed files
... ...
@@ -1046,6 +1046,14 @@ func (v Verbose) Infof(format string, args ...interface{}) {
1046 1046
 	}
1047 1047
 }
1048 1048
 
1049
+// InfoDepth is equivalent to the global InfoDepth function, guarded by the value of v.
1050
+// See the documentation of V for usage.
1051
+func (v Verbose) InfoDepth(depth int, args ...interface{}) {
1052
+	if v {
1053
+		logging.printDepth(infoLog, depth, args...)
1054
+	}
1055
+}
1056
+
1049 1057
 // Info logs to the INFO log.
1050 1058
 // Arguments are handled in the manner of fmt.Print; a newline is appended if missing.
1051 1059
 func Info(args ...interface{}) {
... ...
@@ -34,6 +34,7 @@ type AllInOneOptions struct {
34 34
 	NodeConfigFile     string
35 35
 	PrintIP            bool
36 36
 	ServiceNetworkCIDR string
37
+	Output             io.Writer
37 38
 }
38 39
 
39 40
 const allInOneLong = `
... ...
@@ -59,7 +60,7 @@ You may also pass --kubeconfig=<path> to connect to an external Kubernetes clust
59 59
 
60 60
 // NewCommandStartAllInOne provides a CLI handler for 'start' command
61 61
 func NewCommandStartAllInOne(basename string, out io.Writer) (*cobra.Command, *AllInOneOptions) {
62
-	options := &AllInOneOptions{MasterOptions: &MasterOptions{Output: out}}
62
+	options := &AllInOneOptions{Output: out, MasterOptions: &MasterOptions{Output: out}}
63 63
 	options.MasterOptions.DefaultsFromName(basename)
64 64
 
65 65
 	cmds := &cobra.Command{
... ...
@@ -227,7 +228,7 @@ func (o AllInOneOptions) StartAllInOne() error {
227 227
 		if err != nil {
228 228
 			return err
229 229
 		}
230
-		fmt.Fprintf(o.MasterOptions.Output, "%s\n", host)
230
+		fmt.Fprintf(o.Output, "%s\n", host)
231 231
 		return nil
232 232
 	}
233 233
 	masterOptions := *o.MasterOptions
... ...
@@ -318,7 +318,7 @@ func (o MasterOptions) CreateCerts() error {
318 318
 		APIServerCAFiles:   o.MasterArgs.APIServerCAFiles,
319 319
 		CABundleFile:       admin.DefaultCABundleFile(o.MasterArgs.ConfigDir.Value()),
320 320
 		PublicAPIServerURL: publicMasterAddr.String(),
321
-		Output:             o.Output,
321
+		Output:             cmdutil.NewGLogWriterV(3),
322 322
 	}
323 323
 	if err := mintAllCertsOptions.Validate(nil); err != nil {
324 324
 		return err
... ...
@@ -19,6 +19,7 @@ import (
19 19
 	configapi "github.com/openshift/origin/pkg/cmd/server/api"
20 20
 	configapilatest "github.com/openshift/origin/pkg/cmd/server/api/latest"
21 21
 	"github.com/openshift/origin/pkg/cmd/server/api/validation"
22
+	cmdutil "github.com/openshift/origin/pkg/cmd/util"
22 23
 	"github.com/openshift/origin/pkg/cmd/util/docker"
23 24
 	utilflags "github.com/openshift/origin/pkg/cmd/util/flags"
24 25
 	"github.com/openshift/origin/pkg/version"
... ...
@@ -257,7 +258,7 @@ func (o NodeOptions) CreateNodeConfig() error {
257 257
 		APIServerCAFiles: []string{admin.DefaultCABundleFile(o.NodeArgs.MasterCertDir)},
258 258
 
259 259
 		NodeClientCAFile: getSignerOptions.CertFile,
260
-		Output:           o.Output,
260
+		Output:           cmdutil.NewGLogWriterV(3),
261 261
 	}
262 262
 
263 263
 	if err := createNodeConfigOptions.Validate(nil); err != nil {
... ...
@@ -1,6 +1,10 @@
1 1
 package util
2 2
 
3
-import "github.com/golang/glog"
3
+import (
4
+	"io"
5
+
6
+	"github.com/golang/glog"
7
+)
4 8
 
5 9
 // GetLogLevel returns the current glog log level
6 10
 func GetLogLevel() (level int) {
... ...
@@ -11,3 +15,23 @@ func GetLogLevel() (level int) {
11 11
 	}
12 12
 	return
13 13
 }
14
+
15
+// NewGLogWriterV returns a new Writer that delegates to `glog.Info` at the
16
+// desired level of verbosity
17
+func NewGLogWriterV(level int) io.Writer {
18
+	return &gLogWriter{
19
+		level: glog.Level(level),
20
+	}
21
+}
22
+
23
+// gLogWriter is a Writer that writes by delegating to `glog.Info`
24
+type gLogWriter struct {
25
+	// level is the default level to log at
26
+	level glog.Level
27
+}
28
+
29
+func (w *gLogWriter) Write(p []byte) (n int, err error) {
30
+	glog.V(w.level).InfoDepth(2, string(p))
31
+
32
+	return len(p), nil
33
+}