From 2c2e7c12717e5e1659bf0d377ea975bdb3faefe2 Mon Sep 17 00:00:00 2001 From: Sharif Elgamal Date: Thu, 18 Apr 2019 17:19:20 -0700 Subject: [PATCH] Reroute logs printed to stdout --- pkg/minikube/machine/cache_images.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/pkg/minikube/machine/cache_images.go b/pkg/minikube/machine/cache_images.go index 4e2a349cbb7c..db7f9012526c 100644 --- a/pkg/minikube/machine/cache_images.go +++ b/pkg/minikube/machine/cache_images.go @@ -17,7 +17,10 @@ limitations under the License. package machine import ( + "bytes" + "io" "io/ioutil" + "log" "os" "os/exec" "path" @@ -288,6 +291,21 @@ func getDstPath(image, dst string) (string, error) { // CacheImage caches an image func CacheImage(image, dst string) error { + // There are go-containerregistry calls here that result in + // ugly log messages getting printed to stdout. Capture + // stdout instead and writing it to info. + r, w, err := os.Pipe() + if err != nil { + return errors.Wrap(err, "opening writing buffer") + } + log.SetOutput(w) + defer func() { + log.SetOutput(os.Stdout) + var buf bytes.Buffer + io.Copy(&buf, r) + glog.Infof(buf.String()) + }() + glog.Infof("Attempting to cache image: %s at %s\n", image, dst) if _, err := os.Stat(dst); err == nil { return nil