1
0
mirror of https://github.com/openshift/source-to-image.git synced 2026-02-05 12:44:54 +01:00

Migrate glog to klog

This commit is contained in:
Adam Kaplan
2019-07-12 14:38:02 -04:00
parent e10e020435
commit 19d753b6f6
6 changed files with 30 additions and 19 deletions

View File

@@ -1,15 +1,22 @@
package main
import (
"flag"
"fmt"
"math/rand"
"os"
"runtime"
"time"
"k8s.io/klog"
"github.com/openshift/source-to-image/pkg/cmd/cli"
)
func init() {
klog.InitFlags(flag.CommandLine)
}
func main() {
rand.Seed(time.Now().UTC().UnixNano())
if len(os.Getenv("GOMAXPROCS")) == 0 {

View File

@@ -5,7 +5,7 @@ import (
"os"
"path/filepath"
log "github.com/golang/glog"
log "k8s.io/klog"
"github.com/openshift/source-to-image/pkg/api"
"github.com/spf13/cobra"
@@ -46,7 +46,7 @@ func SetupGlog(flags *pflag.FlagSet) {
flags.Int32Var(loglevelPtr, "loglevel", 0, "Set the level of log output (0-5)")
}
// FIXME currently glog has only option to redirect output to stderr
// the preferred for S2I would be to redirect to stdout
// FIXME glog had only option to redirect output to stderr
// the preferred for S2I would be to redirect to stdout - klog can support via `klog.SetOutput()`
flag.CommandLine.Set("logtostderr", "true")
}

View File

@@ -5,7 +5,8 @@ import (
"path/filepath"
"runtime"
"github.com/golang/glog"
"k8s.io/klog"
"github.com/openshift/source-to-image/pkg/api"
"github.com/openshift/source-to-image/pkg/api/constants"
"github.com/openshift/source-to-image/pkg/scm/git"
@@ -31,21 +32,21 @@ func (c *Clone) Download(config *api.Config) (*git.SourceInfo, error) {
if len(config.ContextDir) > 0 {
targetSourceDir = filepath.Join(config.WorkingDir, constants.ContextTmp)
glog.V(1).Infof("Downloading %q (%q) ...", config.Source, config.ContextDir)
klog.V(1).Infof("Downloading %q (%q) ...", config.Source, config.ContextDir)
} else {
glog.V(1).Infof("Downloading %q ...", config.Source)
klog.V(1).Infof("Downloading %q ...", config.Source)
}
if !config.IgnoreSubmodules {
glog.V(2).Infof("Cloning sources into %q", targetSourceDir)
klog.V(2).Infof("Cloning sources into %q", targetSourceDir)
} else {
glog.V(2).Infof("Cloning sources (ignoring submodules) into %q", targetSourceDir)
klog.V(2).Infof("Cloning sources (ignoring submodules) into %q", targetSourceDir)
}
cloneConfig := git.CloneConfig{Quiet: true}
err := c.Clone(config.Source, targetSourceDir, cloneConfig)
if err != nil {
glog.V(0).Infof("error: git clone failed: %v", err)
klog.V(0).Infof("error: git clone failed: %v", err)
return nil, err
}
@@ -53,13 +54,13 @@ func (c *Clone) Download(config *api.Config) (*git.SourceInfo, error) {
if err != nil {
return nil, err
}
glog.V(1).Infof("Checked out %q", ref)
klog.V(1).Infof("Checked out %q", ref)
if !config.IgnoreSubmodules {
err = c.SubmoduleUpdate(targetSourceDir, true, true)
if err != nil {
return nil, err
}
glog.V(1).Infof("Updated submodules for %q", ref)
klog.V(1).Infof("Updated submodules for %q", ref)
}
// Record Git's knowledge about file permissions

View File

@@ -11,7 +11,7 @@ import (
"strconv"
"strings"
log "github.com/golang/glog"
log "k8s.io/klog"
"github.com/openshift/source-to-image/pkg/util/cmd"
"github.com/openshift/source-to-image/pkg/util/cygpath"

View File

@@ -8,7 +8,7 @@ import (
"strings"
"sync"
log "github.com/golang/glog"
log "k8s.io/klog"
)
// Logger is a simple interface that is roughly equivalent to glog.

View File

@@ -16,10 +16,11 @@ import (
"testing"
"time"
"k8s.io/klog"
dockertypes "github.com/docker/docker/api/types"
dockercontainer "github.com/docker/docker/api/types/container"
dockerapi "github.com/docker/docker/client"
"github.com/golang/glog"
"github.com/openshift/source-to-image/pkg/api"
"github.com/openshift/source-to-image/pkg/build/strategies"
"github.com/openshift/source-to-image/pkg/docker"
@@ -77,6 +78,8 @@ const (
var engineClient docker.Client
func init() {
klog.InitFlags(nil)
var err error
engineClient, err = docker.NewEngineAPIClient(docker.GetDefaultDockerConfig())
if err != nil {
@@ -161,7 +164,7 @@ var (
func getLogLevel() (level int) {
for level = 5; level >= 0; level-- {
if glog.V(glog.Level(level)) == true {
if klog.V(klog.Level(level)) == true {
break
}
}
@@ -190,14 +193,14 @@ func (i *integrationTest) setup() {
from := flag.CommandLine
if vflag := from.Lookup("v"); vflag != nil {
// the thing here is that we are looking for the bash -v passed into test-integration.sh (with no value),
// but for glog (https://github.com/golang/glog/blob/master/glog.go), one specifies
// but for klog (https://k8s.io/klog/blob/master/klog.go), one specifies
// the logging level with -v=# (i.e. -v=0 or -v=3 or -v=5).
// so, for the changes stemming from issue 133, we 'reuse' the bash -v, and set the highest glog level.
// (if you look at STI's main.go, and setupGlog, it essentially maps glog's -v to --loglevel for use by the sti command)
// so, for the changes stemming from issue 133, we 'reuse' the bash -v, and set the highest klog level.
// (if you look at STI's main.go, and setupGlog, it essentially maps klog's -v to --loglevel for use by the sti command)
//NOTE - passing --loglevel or -v=5 into test-integration.sh does not work
if getLogLevel() != 5 {
vflag.Value.Set("5")
// FIXME currently glog has only option to redirect output to stderr
// FIXME currently klog has only option to redirect output to stderr
// the preferred for STI would be to redirect to stdout
flag.CommandLine.Set("logtostderr", "true")
}