diff --git a/pkg/types/v1/runner.go b/pkg/types/v1/runner.go index 214c3a76738..b1e857ddd2b 100644 --- a/pkg/types/v1/runner.go +++ b/pkg/types/v1/runner.go @@ -53,7 +53,8 @@ func (r RealRunner) Run(command string, args ...string) ([]byte, error) { cmd := r.InitCmd(command, args...) out, err := r.RunCmd(cmd) if err != nil { - r.error(fmt.Sprintf("Error running command: %s", err.Error())) + r.debug(fmt.Sprintf("'%s' command reported an error: %s", command, err.Error())) + r.debug(fmt.Sprintf("'%s' command output: %s", command, out)) } return out, err } @@ -66,12 +67,6 @@ func (r *RealRunner) SetLogger(logger Logger) { r.Logger = logger } -func (r RealRunner) error(msg string) { - if r.Logger != nil { - r.Logger.Error(msg) - } -} - func (r RealRunner) debug(msg string) { if r.Logger != nil { r.Logger.Debug(msg) diff --git a/pkg/types/v1/runner_test.go b/pkg/types/v1/runner_test.go index b8a8b3fb79f..784acd881dc 100644 --- a/pkg/types/v1/runner_test.go +++ b/pkg/types/v1/runner_test.go @@ -21,7 +21,6 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "github.com/sirupsen/logrus" v1mock "github.com/rancher/elemental-toolkit/pkg/mocks" v1 "github.com/rancher/elemental-toolkit/pkg/types/v1" @@ -56,15 +55,16 @@ var _ = Describe("Runner", Label("types", "runner"), func() { It("logs the command when on debug", func() { memLog := &bytes.Buffer{} logger := v1.NewBufferLogger(memLog) - logger.SetLevel(logrus.DebugLevel) + logger.SetLevel(v1.DebugLevel()) r := v1.RealRunner{Logger: logger} _, err := r.Run("echo", "-n", "Some message") Expect(err).To(BeNil()) Expect(memLog.String()).To(ContainSubstring("echo -n Some message")) }) - It("logs when command is not found", func() { + It("logs when command is not found in debug mode", func() { memLog := &bytes.Buffer{} logger := v1.NewBufferLogger(memLog) + logger.SetLevel(v1.DebugLevel()) r := v1.RealRunner{Logger: logger} _, err := r.Run("IAmMissing") Expect(err).NotTo(BeNil())