aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorBence Ferdinandy <bence@ferdinandy.com>2024-07-01 22:04:12 +0200
committerRobin Jarry <robin@jarry.cc>2024-08-04 18:24:42 +0200
commit6079239f341f2a6ff297c160697fe0c1c51aba7c (patch)
tree50a46eaef7cf4c58da3a0c59e453f0cd4fefcccc /lib
parent38c4596960c3008f09c04d0c911dba66eb9537e5 (diff)
downloadaerc-6079239f341f2a6ff297c160697fe0c1c51aba7c.tar.gz
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 <bence@ferdinandy.com> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'lib')
-rw-r--r--lib/hooks/exec.go11
1 files changed, 10 insertions, 1 deletions
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
}