Skip to content

Commit

Permalink
Add stdout and stderr to log info
Browse files Browse the repository at this point in the history
Without this, we are loosing features based on previous logrus
implementation. Now, we will log the stdout and stderr for
each call.

Next to this, we ensure the call of the log. methods will be
ready for the switch to get rid of logrus in the future.

Signed-off-by: Jean-Philippe Evrard <[email protected]>
  • Loading branch information
evrardjp committed Nov 6, 2024
1 parent f20a1dd commit 94e7346
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
7 changes: 4 additions & 3 deletions pkg/checkers/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
log "github.com/sirupsen/logrus"
"os"
"os/exec"
"strings"
)

// Checker is the standard interface to use to check
Expand Down Expand Up @@ -71,15 +72,15 @@ func (rc CommandChecker) RebootRequired() bool {
// is the right thing to do, and we are logging stdout/stderr of the command
// so it should be obvious what is wrong.
if cmd.ProcessState.ExitCode() != 1 {
log.Warnf("sentinel command ended with unexpected exit code: %v", cmd.ProcessState.ExitCode())
log.Warn(fmt.Sprintf("sentinel command ended with unexpected exit code: %v", cmd.ProcessState.ExitCode()), "cmd", strings.Join(cmd.Args, " "), "stdout", bufStdout.String(), "stderr", bufStderr.String())
}
return false
default:
// Something was grossly misconfigured, such as the command path being wrong.
log.Fatalf("Error invoking sentinel command: %v", err)
log.Fatal(fmt.Sprintf("Error invoking sentinel command: %v", err), "cmd", strings.Join(cmd.Args, " "), "stdout", bufStdout.String(), "stderr", bufStderr.String())
}
}
log.Info("checking if reboot is required", "cmd", cmd.Args, "stdout", bufStdout, "stderr", bufStderr)
log.Info("checking if reboot is required", "cmd", strings.Join(cmd.Args, " "), "stdout", bufStdout.String(), "stderr", bufStderr.String())
return true
}

Expand Down
5 changes: 3 additions & 2 deletions pkg/reboot/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/google/shlex"
log "github.com/sirupsen/logrus"
"os/exec"
"strings"
)

// CommandRebooter holds context-information for a reboot with command
Expand All @@ -24,9 +25,9 @@ func (c CommandRebooter) Reboot() error {
cmd.Stderr = bufStderr

if err := cmd.Run(); err != nil {
return fmt.Errorf("error invoking reboot command %s: %v", c.RebootCommand, err)
return fmt.Errorf("error invoking reboot command %s: %v (stdout: %v, stderr: %v)", c.RebootCommand, err, bufStdout.String(), bufStderr.String())
}
log.Info("Invoked reboot command", "cmd", cmd.Args, "stdout", bufStdout, "stderr", bufStderr)
log.Info("Invoked reboot command", "cmd", strings.Join(cmd.Args, " "), "stdout", bufStdout.String(), "stderr", bufStderr.String())
return nil
}

Expand Down

0 comments on commit 94e7346

Please sign in to comment.