Reroute logs printed to stdout
parent
3746fb9994
commit
2c2e7c1271
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue