diff options
author | Bence Ferdinandy <bence@ferdinandy.com> | 2024-07-01 22:04:12 +0200 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2024-08-04 18:24:42 +0200 |
commit | 6079239f341f2a6ff297c160697fe0c1c51aba7c (patch) | |
tree | 50a46eaef7cf4c58da3a0c59e453f0cd4fefcccc /lib | |
parent | 38c4596960c3008f09c04d0c911dba66eb9537e5 (diff) | |
download | aerc-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.go | 11 |
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 } |