Migrate server classes to Flogger

This is the second part of the migration to Flogger. This change
migrates all classes of the 'server' module to Flogger. Classes of the
'httpd' module have been migrated by the predecessor change. 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: I233afc8360af7fef8640394204d0d676cc0d0001
Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
Edwin Kempin
2018-05-04 11:50:06 +02:00
parent 03d2d209b1
commit a655fe03a7
195 changed files with 1513 additions and 1514 deletions

View File

@@ -14,17 +14,16 @@
package com.google.gerrit.server.util;
import com.google.common.flogger.FluentLogger;
import com.google.gerrit.common.data.Capable;
import com.google.gerrit.reviewdb.client.Project;
import java.io.IOException;
import java.util.Map;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public final class MagicBranch {
private static final Logger log = LoggerFactory.getLogger(MagicBranch.class);
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
public static final String NEW_CHANGE = "refs/for/";
// TODO(xchangcheng): remove after 'repo' supports private/wip changes.
@@ -95,16 +94,16 @@ public final class MagicBranch {
blockingFors = repo.getRefDatabase().getRefs(branchName);
} catch (IOException err) {
String projName = project.getName();
log.warn("Cannot scan refs in '" + projName + "'", err);
logger.atWarning().withCause(err).log("Cannot scan refs in '%s'", projName);
return new Capable("Server process cannot read '" + projName + "'");
}
if (!blockingFors.isEmpty()) {
String projName = project.getName();
log.error(
"Repository '"
+ projName
+ "' needs the following refs removed to receive changes: "
+ blockingFors.keySet());
logger
.atSevere()
.log(
"Repository '%s' needs the following refs removed to receive changes: %s",
projName, blockingFors.keySet());
return new Capable("One or more " + branchName + " names blocks change upload");
}

View File

@@ -17,6 +17,7 @@ package com.google.gerrit.server.util;
import static java.nio.charset.StandardCharsets.UTF_8;
import com.google.common.base.Strings;
import com.google.common.flogger.FluentLogger;
import com.google.gerrit.common.Die;
import com.google.gerrit.server.config.GerritServerConfig;
import com.google.gerrit.server.config.SitePaths;
@@ -35,11 +36,10 @@ import org.apache.log4j.helpers.OnlyOnceErrorHandler;
import org.apache.log4j.spi.ErrorHandler;
import org.apache.log4j.spi.LoggingEvent;
import org.eclipse.jgit.lib.Config;
import org.slf4j.LoggerFactory;
@Singleton
public class SystemLog {
private static final org.slf4j.Logger log = LoggerFactory.getLogger(SystemLog.class);
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
public static final String LOG4J_CONFIGURATION = "log4j.configuration";
@@ -90,8 +90,9 @@ public class SystemLog {
if (appender != null) {
async.addAppender(appender);
} else {
log.warn(
"No appender with the name: " + name + " was found. " + name + " logging is disabled");
logger
.atWarning()
.log("No appender with the name: %s was found. %s logging is disabled", name, name);
}
}
async.activateOptions();