Log a warning when a hook exits with error status The hook's exit status and output were always logged, but only at debug level. Change it so that when the exit status is an error (non-zero) it is logged at warning level. Change-Id: I4e7079a897e0d88b3c69f392f634096f477f7780
diff --git a/src/main/java/com/googlesource/gerrit/plugins/hooks/HookTask.java b/src/main/java/com/googlesource/gerrit/plugins/hooks/HookTask.java index 3f6e0c7..7a7189a 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/hooks/HookTask.java +++ b/src/main/java/com/googlesource/gerrit/plugins/hooks/HookTask.java
@@ -119,17 +119,22 @@ log.error("Error running hook {}", hook.toAbsolutePath(), err); } - if (result != null && log.isDebugEnabled()) { - log.debug("hook[{}] exitValue: {}", name, result.getExitValue()); + if (result != null) { + int exitValue = result.getExitValue(); + if (exitValue != 0) { + log.warn("hook[{}] exited with error status: {}", name, exitValue); + } - BufferedReader br = new BufferedReader(new StringReader(result.getOutput())); - try { - String line; - while ((line = br.readLine()) != null) { - log.debug("hook[{}] output: {}", name, line); + if (log.isDebugEnabled()) { + BufferedReader br = new BufferedReader(new StringReader(result.getOutput())); + try { + String line; + while ((line = br.readLine()) != null) { + log.debug("hook[{}] output: {}", name, line); + } + } catch (IOException iox) { + log.error("Error writing hook [{}] output", name, iox); } - } catch (IOException iox) { - log.error("Error writing hook [{}] output", name, iox); } }