Merge branch 'stable-2.16'
* stable-2.16:
Migrate to Flogger
Change-Id: I3a6b3ed4956db51ef83da6a8de19836c4f22ea90
diff --git a/src/main/java/com/googlesource/gerrit/plugins/webhooks/DefaultHttpClientProvider.java b/src/main/java/com/googlesource/gerrit/plugins/webhooks/DefaultHttpClientProvider.java
index 46b48ae..cd034ad 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/webhooks/DefaultHttpClientProvider.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/webhooks/DefaultHttpClientProvider.java
@@ -14,6 +14,7 @@
package com.googlesource.gerrit.plugins.webhooks;
+import com.google.common.flogger.FluentLogger;
import com.google.inject.Inject;
import com.google.inject.Provider;
import java.security.KeyManagementException;
@@ -28,12 +29,10 @@
import org.apache.http.conn.socket.PlainConnectionSocketFactory;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/* HTTP client that doesn't verify remote's SSL certificate */
class DefaultHttpClientProvider extends HttpClientProvider {
- private static final Logger log = LoggerFactory.getLogger(DefaultHttpClientProvider.class);
+ private static final FluentLogger log = FluentLogger.forEnclosingClass();
static final String DEFAULT = "default";
@@ -59,7 +58,7 @@
context.init(null, trustAllCerts, null);
return context;
} catch (KeyManagementException | NoSuchAlgorithmException e) {
- log.warn("Error building SSLContext object", e);
+ log.atWarning().withCause(e).log("Error building SSLContext object");
return null;
}
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/webhooks/EventHandler.java b/src/main/java/com/googlesource/gerrit/plugins/webhooks/EventHandler.java
index ca35e36..986c84e 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/webhooks/EventHandler.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/webhooks/EventHandler.java
@@ -17,6 +17,7 @@
import static com.googlesource.gerrit.plugins.webhooks.RemoteConfig.REMOTE;
import com.google.common.base.Strings;
+import com.google.common.flogger.FluentLogger;
import com.google.gerrit.extensions.annotations.PluginName;
import com.google.gerrit.server.config.PluginConfigFactory;
import com.google.gerrit.server.events.Event;
@@ -25,11 +26,9 @@
import com.google.gerrit.server.project.NoSuchProjectException;
import com.google.inject.Inject;
import org.eclipse.jgit.lib.Config;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
class EventHandler implements EventListener {
- private static final Logger log = LoggerFactory.getLogger(EventHandler.class);
+ private static final FluentLogger log = FluentLogger.forEnclosingClass();
private final PluginConfigFactory configFactory;
private final String pluginName;
@@ -61,17 +60,16 @@
configFactory.getProjectPluginConfigWithInheritance(
projectEvent.getProjectNameKey(), pluginName);
} catch (NoSuchProjectException e) {
- log.warn(
- "Ignoring event for a non-existing project {}, {}",
- projectEvent.getProjectNameKey().get(),
- projectEvent);
+ log.atWarning().log(
+ "Ignoring event for a non-existing project %s, %s",
+ projectEvent.getProjectNameKey().get(), projectEvent);
return;
}
for (String name : cfg.getSubsections(REMOTE)) {
RemoteConfig remote = remoteFactory.create(cfg, name);
if (Strings.isNullOrEmpty(remote.getUrl())) {
- log.warn("remote.{}.url not defined, skipping this remote", name);
+ log.atWarning().log("remote.%s.url not defined, skipping this remote", name);
continue;
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/webhooks/HttpClientProvider.java b/src/main/java/com/googlesource/gerrit/plugins/webhooks/HttpClientProvider.java
index aecb43a..f9afd02 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/webhooks/HttpClientProvider.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/webhooks/HttpClientProvider.java
@@ -14,6 +14,9 @@
package com.googlesource.gerrit.plugins.webhooks;
+import static com.google.common.flogger.LazyArgs.lazy;
+
+import com.google.common.flogger.FluentLogger;
import com.google.inject.Provider;
import org.apache.http.HttpResponse;
import org.apache.http.client.ServiceUnavailableRetryStrategy;
@@ -25,12 +28,10 @@
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.protocol.HttpContext;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/** Provides an HTTP client with SSL capabilities. */
abstract class HttpClientProvider implements Provider<CloseableHttpClient> {
- private static final Logger log = LoggerFactory.getLogger(HttpClientProvider.class);
+ private static final FluentLogger log = FluentLogger.forEnclosingClass();
private static final int CONNECTIONS_PER_ROUTE = 100;
// Up to 2 target instances with the max number of connections per host:
private static final int MAX_CONNECTIONS = 2 * CONNECTIONS_PER_ROUTE;
@@ -85,14 +86,9 @@
}
private void logRetry(String cause, HttpContext context) {
- if (log.isDebugEnabled()) {
- log.debug(
- "Retrying request caused by '"
- + cause
- + "', request: '"
- + context.getAttribute("http.request")
- + "'");
- }
+ log.atFine().log(
+ "Retrying request caused by '%s', request: '%s'",
+ cause, lazy(() -> context.getAttribute("http.request")));
}
private HttpClientConnectionManager create(
diff --git a/src/main/java/com/googlesource/gerrit/plugins/webhooks/HttpResponseHandler.java b/src/main/java/com/googlesource/gerrit/plugins/webhooks/HttpResponseHandler.java
index 0c23b6e..0c5bd24 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/webhooks/HttpResponseHandler.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/webhooks/HttpResponseHandler.java
@@ -18,14 +18,13 @@
import static javax.servlet.http.HttpServletResponse.SC_NO_CONTENT;
import static javax.servlet.http.HttpServletResponse.SC_OK;
+import com.google.common.flogger.FluentLogger;
import com.googlesource.gerrit.plugins.webhooks.HttpResponseHandler.HttpResult;
import java.io.IOException;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ResponseHandler;
import org.apache.http.util.EntityUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
class HttpResponseHandler implements ResponseHandler<HttpResult> {
@@ -39,7 +38,7 @@
}
}
- private static final Logger log = LoggerFactory.getLogger(HttpResponseHandler.class);
+ private static final FluentLogger log = FluentLogger.forEnclosingClass();
@Override
public HttpResult handleResponse(HttpResponse response) {
@@ -57,7 +56,7 @@
try {
return EntityUtils.toString(entity);
} catch (IOException e) {
- log.error("Error parsing entity", e);
+ log.atSevere().withCause(e).log("Error parsing entity");
}
}
return "";
diff --git a/src/main/java/com/googlesource/gerrit/plugins/webhooks/PostTask.java b/src/main/java/com/googlesource/gerrit/plugins/webhooks/PostTask.java
index 0d7fd51..90c03b9 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/webhooks/PostTask.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/webhooks/PostTask.java
@@ -16,6 +16,7 @@
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
+import com.google.common.flogger.FluentLogger;
import com.google.gerrit.server.events.ProjectEvent;
import com.google.inject.assistedinject.Assisted;
import com.google.inject.assistedinject.AssistedInject;
@@ -25,11 +26,9 @@
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import javax.net.ssl.SSLException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
class PostTask implements Runnable {
- private static final Logger log = LoggerFactory.getLogger(PostTask.class);
+ private static final FluentLogger log = FluentLogger.forEnclosingClass();
interface Factory {
PostTask create(ProjectEvent event, RemoteConfig remote);
@@ -71,7 +70,7 @@
try {
Optional<EventProcessor.Request> content = processor.get();
if (!content.isPresent()) {
- log.debug("No content. Webhook [{}] skipped.", remote.getUrl());
+ log.atFine().log("No content. Webhook [%s] skipped.", remote.getUrl());
return;
}
@@ -86,7 +85,7 @@
logRetry(e);
reschedule();
} else {
- log.error("Failed to post: {}", toString(), e);
+ log.atSevere().withCause(e).log("Failed to post: %s", toString());
}
}
}
@@ -96,15 +95,12 @@
}
private void logRetry(String reason) {
- if (log.isDebugEnabled()) {
- log.debug("Retrying {} in {}ms. Reason: {}", toString(), remote.getRetryInterval(), reason);
- }
+ log.atFine().log(
+ "Retrying %s in %dms. Reason: %s", toString(), remote.getRetryInterval(), reason);
}
private void logRetry(Throwable cause) {
- if (log.isDebugEnabled()) {
- log.debug("Retrying {} in {}ms. Cause: {}", toString(), remote.getRetryInterval(), cause);
- }
+ log.atFine().withCause(cause).log("Retrying %s in %dms", toString(), remote.getRetryInterval());
}
@Override