Migrate httpd classes to Flogger
This is the first part of the migration to Flogger. This change migrates all classes of the 'http' module to Flogger. Other modules continue to use slf4j. They should be migrated by follow-up changes. During this migration we try to make the log statements more consistent: - avoid string concatenation - avoid usage of String.format(...) Change-Id: I473c41733b00aa1ceab92fe0dc8cd1c6b347174c Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
@@ -32,6 +32,7 @@ import com.google.common.base.Strings;
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import com.google.common.net.HttpHeaders;
|
||||
import com.google.gerrit.extensions.registration.RegistrationHandle;
|
||||
@@ -92,14 +93,13 @@ import org.apache.commons.lang.StringUtils;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.eclipse.jgit.util.IO;
|
||||
import org.eclipse.jgit.util.RawParseUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@Singleton
|
||||
class HttpPluginServlet extends HttpServlet implements StartPluginListener, ReloadPluginListener {
|
||||
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
|
||||
|
||||
private static final int SMALL_RESOURCE = 128 * 1024;
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final Logger log = LoggerFactory.getLogger(HttpPluginServlet.class);
|
||||
|
||||
private final MimeUtilFileTypeRegistry mimeUtil;
|
||||
private final Provider<String> webUrl;
|
||||
@@ -191,7 +191,7 @@ class HttpPluginServlet extends HttpServlet implements StartPluginListener, Relo
|
||||
try {
|
||||
filter = plugin.getHttpInjector().getInstance(GuiceFilter.class);
|
||||
} catch (RuntimeException e) {
|
||||
log.warn("Plugin {} cannot load GuiceFilter", name, e);
|
||||
logger.atWarning().withCause(e).log("Plugin %s cannot load GuiceFilter", name);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -199,7 +199,7 @@ class HttpPluginServlet extends HttpServlet implements StartPluginListener, Relo
|
||||
ServletContext ctx = PluginServletContext.create(plugin, wrapper.getFullPath(name));
|
||||
filter.init(new WrappedFilterConfig(ctx));
|
||||
} catch (ServletException e) {
|
||||
log.warn("Plugin {} failed to initialize HTTP", name, e);
|
||||
logger.atWarning().withCause(e).log("Plugin %s failed to initialize HTTP", name);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -423,12 +423,12 @@ class HttpPluginServlet extends HttpServlet implements StartPluginListener, Relo
|
||||
&& (name.endsWith(".md") || name.endsWith(".html"))
|
||||
&& size.isPresent()) {
|
||||
if (size.get() <= 0 || size.get() > SMALL_RESOURCE) {
|
||||
log.warn(
|
||||
"Plugin {}: {} omitted from document index. Size {} out of range (0,{}).",
|
||||
pluginName,
|
||||
name.substring(prefix.length()),
|
||||
size.get(),
|
||||
SMALL_RESOURCE);
|
||||
logger
|
||||
.atWarning()
|
||||
.log(
|
||||
"Plugin %s: %s omitted from document index. "
|
||||
+ "Size %d out of range (0,%d).",
|
||||
pluginName, name.substring(prefix.length()), size.get(), SMALL_RESOURCE);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -450,10 +450,11 @@ class HttpPluginServlet extends HttpServlet implements StartPluginListener, Relo
|
||||
if (about == null) {
|
||||
about = entry;
|
||||
} else {
|
||||
log.warn(
|
||||
"Plugin {}: Multiple 'about' documents found; using {}",
|
||||
pluginName,
|
||||
about.getName().substring(prefix.length()));
|
||||
logger
|
||||
.atWarning()
|
||||
.log(
|
||||
"Plugin %s: Multiple 'about' documents found; using %s",
|
||||
pluginName, about.getName().substring(prefix.length()));
|
||||
}
|
||||
} else {
|
||||
docs.add(entry);
|
||||
@@ -731,7 +732,10 @@ class HttpPluginServlet extends HttpServlet implements StartPluginListener, Relo
|
||||
}
|
||||
return def;
|
||||
} catch (IOException e) {
|
||||
log.warn("Error getting {} for plugin {}, using default", attr, plugin.getName(), e);
|
||||
logger
|
||||
.atWarning()
|
||||
.withCause(e)
|
||||
.log("Error getting %s for plugin %s, using default", attr, plugin.getName());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@@ -18,6 +18,7 @@ import static com.google.gerrit.extensions.api.lfs.LfsDefinitions.CONTENTTYPE_VN
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static javax.servlet.http.HttpServletResponse.SC_NOT_IMPLEMENTED;
|
||||
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import com.google.gerrit.extensions.registration.RegistrationHandle;
|
||||
import com.google.gerrit.httpd.resources.Resource;
|
||||
import com.google.gerrit.server.config.GerritServerConfig;
|
||||
@@ -45,14 +46,14 @@ import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@Singleton
|
||||
public class LfsPluginServlet extends HttpServlet
|
||||
implements StartPluginListener, ReloadPluginListener {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final Logger log = LoggerFactory.getLogger(LfsPluginServlet.class);
|
||||
|
||||
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
|
||||
|
||||
private static final String MESSAGE_LFS_NOT_CONFIGURED =
|
||||
"{\"message\":\"No LFS plugin is configured to handle LFS requests.\"}";
|
||||
|
||||
@@ -139,7 +140,7 @@ public class LfsPluginServlet extends HttpServlet
|
||||
try {
|
||||
guiceFilter = plugin.getHttpInjector().getInstance(GuiceFilter.class);
|
||||
} catch (RuntimeException e) {
|
||||
log.warn("Plugin {} cannot load GuiceFilter", name, e);
|
||||
logger.atWarning().withCause(e).log("Plugin %s cannot load GuiceFilter", name);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -147,7 +148,7 @@ public class LfsPluginServlet extends HttpServlet
|
||||
ServletContext ctx = PluginServletContext.create(plugin, "/");
|
||||
guiceFilter.init(new WrappedFilterConfig(ctx));
|
||||
} catch (ServletException e) {
|
||||
log.warn("Plugin {} failed to initialize HTTP", name, e);
|
||||
logger.atWarning().withCause(e).log("Plugin %s failed to initialize HTTP", name);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@@ -15,6 +15,7 @@
|
||||
package com.google.gerrit.httpd.plugins;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import com.google.gerrit.common.Version;
|
||||
import com.google.gerrit.server.plugins.Plugin;
|
||||
import java.io.InputStream;
|
||||
@@ -29,11 +30,9 @@ import java.util.concurrent.ConcurrentMap;
|
||||
import javax.servlet.RequestDispatcher;
|
||||
import javax.servlet.Servlet;
|
||||
import javax.servlet.ServletContext;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
class PluginServletContext {
|
||||
private static final Logger log = LoggerFactory.getLogger(PluginServletContext.class);
|
||||
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
|
||||
|
||||
static ServletContext create(Plugin plugin, String contextPath) {
|
||||
return (ServletContext)
|
||||
@@ -155,7 +154,7 @@ class PluginServletContext {
|
||||
|
||||
@Override
|
||||
public void log(String msg, Throwable reason) {
|
||||
log.warn("[plugin {}] {}", plugin.getName(), msg, reason);
|
||||
logger.atWarning().withCause(reason).log("[plugin %s] %s", plugin.getName(), msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user