diff --git a/cmd/camput/camput.go b/cmd/camput/camput.go index 043391be1..bf2482222 100644 --- a/cmd/camput/camput.go +++ b/cmd/camput/camput.go @@ -163,7 +163,9 @@ func newUploader() *Uploader { httpStats, _ = tr.(*httputil.StatsTransport) cc.SetHTTPClient(&http.Client{Transport: tr}) } - if !*cmdmain.FlagVerbose { + if *cmdmain.FlagVerbose { + cc.SetLogger(log.New(cmdmain.Stderr, "", log.LstdFlags)) + } else { cc.SetLogger(nil) } diff --git a/cmd/camput/files.go b/cmd/camput/files.go index f3042e1ba..239187d7a 100644 --- a/cmd/camput/files.go +++ b/cmd/camput/files.go @@ -145,6 +145,12 @@ func (c *fileCmd) RunCommand(args []string) error { if c.deleteAfterUpload && !c.filePermanodes { return cmdmain.UsageError("Can't set use --delete_after_upload without --filenodes") } + // TODO(mpl): do it for other modes too. Or even better, do it once for all modes. + if *cmdmain.FlagVerbose { + log.SetOutput(cmdmain.Stderr) + } else { + log.SetOutput(ioutil.Discard) + } up := getUploader() if c.memstats { sr := new(statspkg.Receiver) @@ -247,9 +253,6 @@ func (c *fileCmd) RunCommand(args []string) error { vlog.Printf("Directories not supported in vivify mode; skipping %v\n", filename) continue } - if !*cmdmain.FlagVerbose { - log.SetOutput(ioutil.Discard) - } t := up.NewTreeUpload(filename) t.Start() lastPut, err = t.Wait() diff --git a/pkg/test/world.go b/pkg/test/world.go index bba3609f4..5795bb227 100644 --- a/pkg/test/world.go +++ b/pkg/test/world.go @@ -236,9 +236,24 @@ func (w *World) Cmd(binary string, args ...string) *exec.Cmd { } func (w *World) CmdWithEnv(binary string, env []string, args ...string) *exec.Cmd { - cmd := exec.Command(filepath.Join(w.camRoot, "bin", binary), args...) + hasVerbose := func() bool { + for _, v := range args { + if v == "-verbose" || v == "--verbose" { + return true + } + } + return false + } + var cmd *exec.Cmd switch binary { case "camget", "camput", "camtool", "cammount": + // TODO(mpl): lift the camput restriction when we have a unified logging mechanism + if binary == "camput" && !hasVerbose() { + // camput and camtool are the only ones to have a -verbose flag through cmdmain + // but camtool is never used. (and cammount does not even have a -verbose). + args = append([]string{"-verbose"}, args...) + } + cmd = exec.Command(filepath.Join(w.camRoot, "bin", binary), args...) clientConfigDir := filepath.Join(w.camRoot, "config", "dev-client-dir") cmd.Env = append([]string{ "CAMLI_CONFIG_DIR=" + clientConfigDir, @@ -295,7 +310,7 @@ func RunCmd(c *exec.Cmd) (output string, err error) { c.Stdout = &stdout err = c.Run() if err != nil { - return "", fmt.Errorf("Error running command %+v: Stdout:\n%s\nStderrr:\n%s\n", c, stdout.String(), stderr.String()) + return "", fmt.Errorf("Error running command %+v: Stdout:\n%s\nStderr:\n%s\n", c, stdout.String(), stderr.String()) } return stdout.String(), nil }