Skip to content

Commit

Permalink
moved output to glog
Browse files Browse the repository at this point in the history
  • Loading branch information
stevekuznetsov committed Apr 8, 2016
1 parent 561e4fa commit 0ac16e4
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
7 changes: 3 additions & 4 deletions pkg/cmd/server/admin/create_keypair.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"os"
"path/filepath"

"github.com/golang/glog"
"github.com/spf13/cobra"

kcmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
Expand Down Expand Up @@ -86,15 +85,15 @@ func (o CreateKeyPairOptions) Validate(args []string) error {
}

func (o CreateKeyPairOptions) CreateKeyPair() error {
glog.V(4).Infof("Creating a key pair with: %#v", o)
fmt.Fprintf(o.Output, "Creating a key pair with: %#v", o)

if !o.Overwrite {
if _, err := os.Stat(o.PrivateKeyFile); err == nil {
glog.V(3).Infof("Keeping existing private key file %s\n", o.PrivateKeyFile)
fmt.Fprintf(o.Output, "Keeping existing private key file %s\n", o.PrivateKeyFile)
return nil
}
if _, err := os.Stat(o.PublicKeyFile); err == nil {
glog.V(3).Infof("Keeping existing public key file %s\n", o.PublicKeyFile)
fmt.Fprintf(o.Output, "Keeping existing public key file %s\n", o.PublicKeyFile)
return nil
}
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/cmd/server/start/start_allinone.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ func (o *AllInOneOptions) Complete() error {
o.MasterOptions.MasterArgs.NetworkArgs.NetworkPluginName = o.NodeArgs.NetworkPluginName
o.MasterOptions.MasterArgs.NetworkArgs.ServiceNetworkCIDR = o.ServiceNetworkCIDR

// delegated commands should use glog
o.MasterOptions.Output = util.NewGLogWriter(3)

masterAddr, err := o.MasterOptions.MasterArgs.GetMasterAddress()
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/server/start/start_master.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ func (o MasterOptions) CreateCerts() error {
APIServerCAFiles: o.MasterArgs.APIServerCAFiles,
CABundleFile: admin.DefaultCABundleFile(o.MasterArgs.ConfigDir.Value()),
PublicAPIServerURL: publicMasterAddr.String(),
Output: o.Output,
Output: util.NewGLogWriter(4),
}
if err := mintAllCertsOptions.Validate(nil); err != nil {
return err
Expand Down
24 changes: 23 additions & 1 deletion pkg/cmd/util/log.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package util

import "github.com/golang/glog"
import (
"io"

"github.com/golang/glog"
)

// GetLogLevel returns the current glog log level
func GetLogLevel() (level int) {
Expand All @@ -11,3 +15,21 @@ func GetLogLevel() (level int) {
}
return
}

// NewGLogWriter returns a new Writer that delegates to `glog.Info` at the
// desired level of verbosity
func NewGLogWriter(level int) io.Writer {
return &gLogWriter{
level: level,
}
}

// gLogWriter is a Writer that writes by delegating to `glog.Info`
type gLogWriter struct {
// level is the default level to log at
level int
}

func (w *gLogWriter) Write(p []byte) (n int, err error) {
glog.V(w.level).Info(p)
}

0 comments on commit 0ac16e4

Please sign in to comment.