Skip to content

Commit

Permalink
Update glogging to always set level, and to respect glog.level
Browse files Browse the repository at this point in the history
  • Loading branch information
smarterclayton committed May 18, 2016
1 parent cf6465c commit 23e7eb8
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 24 deletions.
4 changes: 2 additions & 2 deletions pkg/build/builder/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func updateBuildRevision(c client.BuildInterface, build *api.Build, sourceInfo *
glog.V(4).Infof("Setting build revision to %#v", build.Spec.Revision.Git)
_, err := c.UpdateDetails(build)
if err != nil {
glog.Infof("error: An error occurred saving build revision: %v", err)
glog.V(0).Infof("error: An error occurred saving build revision: %v", err)
}
}

Expand Down Expand Up @@ -137,7 +137,7 @@ func execPostCommitHook(client DockerClient, postCommitSpec api.BuildPostCommitS
// Post commit hook is not set, return early.
return nil
}
glog.Infof("Running post commit hook with image %s ...", image)
glog.V(1).Infof("Running post commit hook with image %s ...", image)
glog.V(4).Infof("Post commit hook spec: %+v", postCommitSpec)

if script != "" {
Expand Down
12 changes: 6 additions & 6 deletions pkg/build/builder/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (d *DockerBuilder) Build() error {
}

if err := removeImage(d.dockerClient, buildTag); err != nil {
glog.Infof("warning: Failed to remove temporary build tag %v: %v", buildTag, err)
glog.V(0).Infof("warning: Failed to remove temporary build tag %v: %v", buildTag, err)
}

if push {
Expand All @@ -116,11 +116,11 @@ func (d *DockerBuilder) Build() error {
if authPresent {
glog.V(4).Infof("Authenticating Docker push with user %q", pushAuthConfig.Username)
}
glog.Infof("Pushing image %s ...", pushTag)
glog.V(1).Infof("Pushing image %s ...", pushTag)
if err := pushImage(d.dockerClient, pushTag, pushAuthConfig); err != nil {
return fmt.Errorf("Failed to push image: %v", err)
}
glog.Infof("Push successful")
glog.V(1).Infof("Push successful")
}
return nil
}
Expand All @@ -135,10 +135,10 @@ func (d *DockerBuilder) copySecrets(secrets []api.SecretBuildSource, buildDir st
return err
}
srcDir := filepath.Join(strategy.SecretBuildSourceBaseMountPath, s.Secret.Name)
glog.Infof("Copying files from the build secret %q to %q", s.Secret.Name, filepath.Clean(s.DestinationDir))
glog.V(3).Infof("Copying files from the build secret %q to %q", s.Secret.Name, filepath.Clean(s.DestinationDir))
out, err := exec.Command("cp", "-vrf", srcDir+"/.", dstDir+"/").Output()
if err != nil {
glog.Infof("Secret %q failed to copy: %q", s.Secret.Name, string(out))
glog.V(4).Infof("Secret %q failed to copy: %q", s.Secret.Name, string(out))
return err
}
// See what is copied where when debugging.
Expand Down Expand Up @@ -239,7 +239,7 @@ func (d *DockerBuilder) buildLabels(dir string) []dockerfile.KeyValue {
sourceInfo, errors = d.gitClient.GetInfo(dir)
if len(errors) > 0 {
for _, e := range errors {
glog.Infof("warning: Unable to retrieve Git info: %v", e.Error())
glog.V(0).Infof("warning: Unable to retrieve Git info: %v", e.Error())
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/build/builder/dockerutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func dockerRun(client DockerClient, createOpts docker.CreateContainerOptions, lo
removeContainer := func() {
glog.V(4).Infof("Removing container %q ...", containerName)
if err := client.RemoveContainer(docker.RemoveContainerOptions{ID: c.ID}); err != nil {
glog.Infof("warning: Failed to remove container %q: %v", containerName, err)
glog.V(0).Infof("warning: Failed to remove container %q: %v", containerName, err)
} else {
glog.V(4).Infof("Removed container %q", containerName)
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/build/builder/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func fetchSource(dockerClient DockerClient, dir string, build *api.Build, urlTim
sourceInfo, errs = gitClient.GetInfo(dir)
if len(errs) > 0 {
for _, e := range errs {
glog.Infof("error: Unable to retrieve Git info: %v", e)
glog.V(0).Infof("error: Unable to retrieve Git info: %v", e)
}
}
}
Expand Down Expand Up @@ -176,7 +176,7 @@ func extractInputBinary(in io.Reader, source *api.BinaryBuildSource, dir string)
return nil
}

glog.Infof("Receiving source from STDIN as archive ...")
glog.V(1).Infof("Receiving source from STDIN as archive ...")

cmd := exec.Command("bsdtar", "-x", "-o", "-m", "-f", "-", "-C", dir)
cmd.Stdin = in
Expand All @@ -193,7 +193,7 @@ func extractGitSource(gitClient GitClient, gitSource *api.GitBuildSource, revisi
return false, nil
}

glog.Infof("Downloading %q ...", gitSource.URI)
glog.V(0).Infof("Downloading %q ...", gitSource.URI)

// Check source URI, trying to connect to the server only if not using a proxy.
if err := checkSourceURI(gitClient, gitSource.URI, timeout); err != nil {
Expand Down Expand Up @@ -315,7 +315,7 @@ func extractSourceFromImage(dockerClient DockerClient, image, buildDir string, i
}

if !exists || forcePull {
glog.Infof("Pulling image %q ...", image)
glog.V(0).Infof("Pulling image %q ...", image)
if err := dockerClient.PullImage(docker.PullImageOptions{Repository: image}, dockerAuth); err != nil {
return fmt.Errorf("error pulling image %v: %v", image, err)
}
Expand Down
23 changes: 13 additions & 10 deletions pkg/build/builder/sti.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,12 @@ type S2IBuilder struct {

// NewS2IBuilder creates a new STIBuilder instance
func NewS2IBuilder(dockerClient DockerClient, dockerSocket string, buildsClient client.BuildInterface, build *api.Build, gitClient GitClient, cgLimits *s2iapi.CGroupLimits) *S2IBuilder {
glog.V(0).Infof("level 0")
glog.V(1).Infof("level 1")
glog.V(2).Infof("level 2")
glog.V(3).Infof("level 3")
// delegate to internal implementation passing default implementation of builderFactory and validator
return newS2IBuilder(dockerClient, dockerSocket, buildsClient, build, gitClient, runtimeBuilderFactory{}, runtimeConfigValidator{}, cgLimits)

}

// newS2IBuilder is the internal factory function to create STIBuilder based on parameters. Used for testing.
Expand Down Expand Up @@ -252,7 +255,7 @@ func (s *S2IBuilder) Build() error {
}

if err := removeImage(s.dockerClient, buildTag); err != nil {
glog.Infof("warning: Failed to remove temporary build tag %v: %v", buildTag, err)
glog.V(0).Infof("warning: Failed to remove temporary build tag %v: %v", buildTag, err)
}

if push {
Expand All @@ -262,27 +265,27 @@ func (s *S2IBuilder) Build() error {
dockercfg.PushAuthType,
)
if authPresent {
glog.Infof("Using provided push secret for pushing %s image", pushTag)
glog.V(2).Infof("Using provided push secret for pushing %s image", pushTag)
} else {
glog.Infof("No push secret provided")
glog.V(2).Infof("No push secret provided")
}
glog.Infof("Pushing %s image ...", pushTag)
glog.V(0).Infof("Pushing %s image ...", pushTag)
if err := pushImage(s.dockerClient, pushTag, pushAuthConfig); err != nil {
// write extended error message to assist in problem resolution
msg := fmt.Sprintf("Failed to push image. Response from registry is: %v", err)
if authPresent {
glog.Infof("Registry server Address: %s", pushAuthConfig.ServerAddress)
glog.Infof("Registry server User Name: %s", pushAuthConfig.Username)
glog.Infof("Registry server Email: %s", pushAuthConfig.Email)
glog.V(3).Infof("Registry server Address: %s", pushAuthConfig.ServerAddress)
glog.V(3).Infof("Registry server User Name: %s", pushAuthConfig.Username)
glog.V(3).Infof("Registry server Email: %s", pushAuthConfig.Email)
passwordPresent := "<<empty>>"
if len(pushAuthConfig.Password) > 0 {
passwordPresent = "<<non-empty>>"
}
glog.Infof("Registry server Password: %s", passwordPresent)
glog.V(3).Infof("Registry server Password: %s", passwordPresent)
}
return errors.New(msg)
}
glog.Infof("Successfully pushed %s", pushTag)
glog.V(1).Infof("Successfully pushed %s", pushTag)
}
return nil
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/util/glog/glog.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,13 @@ func (f file) Is(level int) bool {
}

func (f file) V(level int) Logger {
// only log things that glog allows
if !glog.V(glog.Level(level)) {
return None
}
// send anything above our level to glog
if level > f.level {
return Log.V(level)
return Log
}
return f
}
Expand Down

0 comments on commit 23e7eb8

Please sign in to comment.