From 1932f38872f4e2cf47739d507507a056a7a7b5ea Mon Sep 17 00:00:00 2001 From: Christopher Campbell Date: Thu, 23 Jan 2025 10:48:20 -0500 Subject: [PATCH] fixes issue-2341 wrt logging and stdout/stderr --- cli/cli/commands/root.go | 13 +++++++------ cli/cli/commands/service/exec/exec.go | 3 ++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/cli/cli/commands/root.go b/cli/cli/commands/root.go index f81cd735e8..79d4e3d21d 100644 --- a/cli/cli/commands/root.go +++ b/cli/cli/commands/root.go @@ -8,6 +8,12 @@ package commands import ( "encoding/json" "fmt" + "io" + "net/http" + "os" + "strings" + "time" + "github.com/Masterminds/semver/v3" "github.com/kurtosis-tech/kurtosis/cli/cli/command_str_consts" "github.com/kurtosis-tech/kurtosis/cli/cli/commands/analytics" @@ -47,11 +53,6 @@ import ( "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/spf13/pflag" - "io" - "net/http" - "os" - "strings" - "time" ) const ( @@ -186,7 +187,7 @@ func setupCLILogs(cmd *cobra.Command) error { if err != nil { return stacktrace.Propagate(err, "Could not parse log level string '%v'", logLevelStr) } - logrus.SetOutput(cmd.OutOrStdout()) + logrus.SetOutput(cmd.OutOrStderr()) logrus.SetLevel(logLevel) return nil } diff --git a/cli/cli/commands/service/exec/exec.go b/cli/cli/commands/service/exec/exec.go index f479564f57..08c80591bb 100644 --- a/cli/cli/commands/service/exec/exec.go +++ b/cli/cli/commands/service/exec/exec.go @@ -157,6 +157,7 @@ func run( if successResult.GetExitCode() != 0 { return stacktrace.NewError("The command was successfully executed but returned a non-zero exit code: '%d'. Output was:\n%v", successResult.GetExitCode(), successResult.GetOutput()) } - out.PrintOutLn(fmt.Sprintf("The command was successfully executed and returned '%d'. Output was:\n%v", successResult.GetExitCode(), successResult.GetOutput())) + out.PrintErrLn(fmt.Sprintf("The command was successfully executed and returned '%d'.", successResult.GetExitCode())) + out.PrintOutLn(successResult.GetOutput()) return nil }