Merge branch 'stable-2.15' * stable-2.15: More logging improvements to help tracking down hook problems Clarify usage of logging set-level command in documentation Update debug documentation to enable debugging for the whole package Change-Id: I86474c9fb38708a6b74570e4c91f8ef4c2ba834e
diff --git a/src/main/java/com/googlesource/gerrit/plugins/hooks/HookExecutor.java b/src/main/java/com/googlesource/gerrit/plugins/hooks/HookExecutor.java index 4a5f6bb..42d4e75 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/hooks/HookExecutor.java +++ b/src/main/java/com/googlesource/gerrit/plugins/hooks/HookExecutor.java
@@ -46,6 +46,7 @@ HookResult submit(String projectName, Path hook, HookArgs args) { if (!Files.exists(hook)) { + log.debug("Hook file not found: {}", hook); return null; } HookTask.Sync hookTask = new HookTask.Sync(projectName, hook, args); @@ -56,10 +57,10 @@ try { return task.get(timeout, TimeUnit.SECONDS); } catch (TimeoutException e) { - message = "Synchronous hook timed out " + hook.toAbsolutePath(); + message = "Synchronous hook timed out " + hook; log.error(message); } catch (Exception e) { - message = "Error running hook " + hook.toAbsolutePath(); + message = "Error running hook " + hook; log.error(message, e); } task.cancel(true);
diff --git a/src/main/java/com/googlesource/gerrit/plugins/hooks/HookFactory.java b/src/main/java/com/googlesource/gerrit/plugins/hooks/HookFactory.java index c3ca6e1..f3d8293 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/hooks/HookFactory.java +++ b/src/main/java/com/googlesource/gerrit/plugins/hooks/HookFactory.java
@@ -23,9 +23,13 @@ import java.nio.file.Path; import java.nio.file.Paths; import org.eclipse.jgit.lib.Config; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; @Singleton public class HookFactory { + private static final Logger log = LoggerFactory.getLogger(HookFactory.class); + private final HookQueue queue; private final HookExecutor syncHookExecutor; private final Config config; @@ -50,11 +54,14 @@ } else { this.hooksPath = sitePaths.hooks_dir; } + log.info("hooks.path: {}", this.hooksPath); } private Path getHookPath(String configName, String defaultName) { String v = config.getString("hooks", null, configName); - return hooksPath.resolve(firstNonNull(v, defaultName)); + Path hookPath = hooksPath.resolve(firstNonNull(v, defaultName)); + log.info("hooks.{} resolved to {}", configName, hookPath); + return hookPath; } public Hook createAsync(String configName, String defaultName) {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/hooks/HookQueue.java b/src/main/java/com/googlesource/gerrit/plugins/hooks/HookQueue.java index bc7e5eb..fb3c5a8 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/hooks/HookQueue.java +++ b/src/main/java/com/googlesource/gerrit/plugins/hooks/HookQueue.java
@@ -20,8 +20,12 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.concurrent.ScheduledExecutorService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; class HookQueue implements LifecycleListener { + private static final Logger log = LoggerFactory.getLogger(HookQueue.class); + private final WorkQueue workQueue; private ScheduledExecutorService queue; @@ -36,9 +40,11 @@ } void submit(String projectName, Path hook, HookArgs args) { - if (Files.exists(hook)) { - queue.submit(new HookTask.Async(projectName, hook, args)); + if (!Files.exists(hook)) { + log.debug("Hook file not found: {}", hook.toAbsolutePath()); + return; } + queue.submit(new HookTask.Async(projectName, hook, args)); } @Override
diff --git a/src/main/resources/Documentation/config.md b/src/main/resources/Documentation/config.md index 778f4cc..e3aa1b9 100644 --- a/src/main/resources/Documentation/config.md +++ b/src/main/resources/Documentation/config.md
@@ -102,12 +102,18 @@ debug level. To make debug logs visible in Gerrit's log file, debug logging must be -enabled for `com.googlesource.gerrit.plugins.hooks.HookTask`. This can be -done by editing the `log4j.properties` file (requires a Gerrit restart) or -by setting the log level at runtime with the ssh command: +enabled for the `com.googlesource.gerrit.plugins.hooks` package. This can be +done by setting the log level at runtime with the ssh command: ``` - ssh -p 29418 user@gerrit gerrit logging set-level DEBUG com.googlesource.gerrit.plugins.hooks.HookTask + ssh -p 29418 user@gerrit gerrit logging set-level DEBUG com.googlesource.gerrit.plugins.hooks ``` +Note that setting the log level at runtime only works for loggers that +have already been created. Loggers that get created after the level was +set will still be created with the default level. + +To set the level for all loggers, it is necessary to do it by editing the +`log4j.properties` file. This requires the Gerrit server to be restarted. + [1]: ../../../Documentation/config-gerrit.html#gerrit.canonicalWebUrl