summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Borowitz <dborowitz@google.com>2018-09-27 13:40:36 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2018-09-27 13:40:36 +0000
commit07cffc59ea0303946ce434dd64d3f9c3111a4616 (patch)
tree6d5eb7e46305ee28197be389aed7415e8aa152fc
parent66db48d4c700c874f4c8a1b42c8d93df299cbc90 (diff)
parent2adf5885b9bd93258bd1471c8d0a51b9653912bf (diff)
Merge "Support 3 arguments for TraceTimer"
-rw-r--r--java/com/google/gerrit/server/logging/TraceContext.java20
1 files changed, 20 insertions, 0 deletions
diff --git a/java/com/google/gerrit/server/logging/TraceContext.java b/java/com/google/gerrit/server/logging/TraceContext.java
index 977baa585d..d68874039b 100644
--- a/java/com/google/gerrit/server/logging/TraceContext.java
+++ b/java/com/google/gerrit/server/logging/TraceContext.java
@@ -192,6 +192,21 @@ public class TraceContext implements AutoCloseable {
return new TraceTimer(format, arg1, arg2);
}
+ /**
+ * Opens a new timer that logs the time for an operation if request tracing is enabled.
+ *
+ * <p>If request tracing is not enabled this is a no-op.
+ *
+ * @param format the message format string
+ * @param arg1 first argument for the message
+ * @param arg2 second argument for the message
+ * @param arg3 third argument for the message
+ * @return the trace timer
+ */
+ public static TraceTimer newTimer(String format, Object arg1, Object arg2, Object arg3) {
+ return new TraceTimer(format, arg1, arg2, arg3);
+ }
+
public static class TraceTimer implements AutoCloseable {
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
@@ -210,6 +225,11 @@ public class TraceContext implements AutoCloseable {
this(elapsedMs -> logger.atFine().log(format + " (%d ms)", arg1, arg2, elapsedMs));
}
+ private TraceTimer(
+ String format, @Nullable Object arg1, @Nullable Object arg2, @Nullable Object arg3) {
+ this(elapsedMs -> logger.atFine().log(format + " (%d ms)", arg1, arg2, arg3, elapsedMs));
+ }
+
private TraceTimer(Consumer<Long> logFn) {
this.logFn = logFn;
this.stopwatch = Stopwatch.createStarted();