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 13, 2016
1 parent baf4504 commit 43459aa
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 7 deletions.
1 change: 1 addition & 0 deletions hack/util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ function configure_os_server {
--public-master="${API_SCHEME}://${PUBLIC_MASTER_HOST}:${API_PORT}"

echo "[INFO] Creating OpenShift node config"
echo "[DEBUG] Have hostnames: ${KUBELET_HOST}"
openshift admin create-node-config \
--listen="${KUBELET_SCHEME}://${KUBELET_BIND_HOST}:${KUBELET_PORT}" \
--node-dir="${NODE_CONFIG_DIR}" \
Expand Down
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
7 changes: 6 additions & 1 deletion pkg/cmd/server/start/start_allinone.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ You may also pass --kubeconfig=<path> to connect to an external Kubernetes clust

// NewCommandStartAllInOne provides a CLI handler for 'start' command
func NewCommandStartAllInOne(basename string, out io.Writer) (*cobra.Command, *AllInOneOptions) {
options := &AllInOneOptions{MasterOptions: &MasterOptions{Output: out}}
options := &AllInOneOptions{
MasterOptions: &MasterOptions{
// delegated commands should use glog instead of writing to the output stream
Output: cmdutil.NewGLogWriterV(3),
},
}
options.MasterOptions.DefaultsFromName(basename)

cmds := &cobra.Command{
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: cmdutil.NewGLogWriterV(3),
}
if err := mintAllCertsOptions.Validate(nil); err != nil {
return err
Expand Down
26 changes: 25 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,23 @@ func GetLogLevel() (level int) {
}
return
}

// NewGLogWriterV returns a new Writer that delegates to `glog.Info` at the
// desired level of verbosity
func NewGLogWriterV(level int) io.Writer {
return &gLogWriter{
level: glog.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 glog.Level
}

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

return len(p), nil
}

0 comments on commit 43459aa

Please sign in to comment.