Skip to content

Commit

Permalink
Merge pull request #4115 from sharifelgamal/4007
Browse files Browse the repository at this point in the history
Reroute logs printed directly to stdout
  • Loading branch information
sharifelgamal committed Apr 23, 2019
2 parents 587d6ed + 2c2e7c1 commit 5e8160b
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions pkg/minikube/machine/cache_images.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ limitations under the License.
package machine

import (
"bytes"
"io"
"io/ioutil"
"log"
"os"
"os/exec"
"path"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5e8160b

Please sign in to comment.