From 6079239f341f2a6ff297c160697fe0c1c51aba7c Mon Sep 17 00:00:00 2001 From: Bence Ferdinandy Date: Mon, 1 Jul 2024 22:04:12 +0200 Subject: hooks: add logging for STDOUT and STDERR Currently the only feedback we have from hooks is the error code. Log STDOUT on loglevel TRACE and log STDERR on loglevel ERROR if the command exists with an error. Signed-off-by: Bence Ferdinandy Acked-by: Robin Jarry --- lib/hooks/exec.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/hooks/exec.go b/lib/hooks/exec.go index ecc33b28..71542c99 100644 --- a/lib/hooks/exec.go +++ b/lib/hooks/exec.go @@ -1,6 +1,7 @@ package hooks import ( + "bytes" "os" "os/exec" @@ -16,7 +17,15 @@ func RunHook(h HookType) error { log.Debugf("hooks: running command %q (env %v)", cmd, env) proc := exec.Command("sh", "-c", cmd) + var outb, errb bytes.Buffer + proc.Stdout = &outb + proc.Stderr = &errb proc.Env = os.Environ() proc.Env = append(proc.Env, env...) - return proc.Run() + err := proc.Run() + log.Tracef("hooks: %q stdout: %s", cmd, outb.String()) + if err != nil { + log.Errorf("hooks:%q stderr: %s", cmd, errb.String()) + } + return err } -- cgit